@@ -4,7 +4,7 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidCurveFitting/IFit.h"
#include "MantidCurveFitting/IDomainCreator.h"

namespace Mantid
{
@@ -45,34 +45,26 @@ namespace Mantid
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport FitMW : public IFit
class DLLExport FitMW : public IDomainCreator
{
public:
/// Default constructor
FitMW() : IFit() {};
/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const { return "FitMW";}
/// Algorithm's version for identification overriding a virtual method
virtual int version() const { return (1);}
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "Optimization";}

protected:
/// Sets documentation strings for this algorithm
virtual void initDocs();

/// declare properties that specify the dataset within the workspace to fit to.
virtual void declareDatasetProperties();
/// Create a domain from the input workspace
virtual void createDomain(boost::shared_ptr<API::FunctionDomain>&, boost::shared_ptr<API::FunctionValues>&);


void createOutputWorkspace(
const std::string& baseName,
boost::shared_ptr<API::FunctionDomain> domain,
boost::shared_ptr<API::FunctionValues> values
);
protected:
/// Constructor
FitMW(API::Algorithm* fit):IDomainCreator(fit){}
/// A friend that can create instances of this class
friend class Fit;

/// Pointer to the fitting function
API::IFunction_sptr m_function;
/// The input MareixWorkspace
boost::shared_ptr<API::MatrixWorkspace> m_matrixWorkspace;
/// The workspace index
@@ -1,5 +1,5 @@
#ifndef MANTID_CURVEFITTING_IFIT_H_
#define MANTID_CURVEFITTING_IFIT_H_
#ifndef MANTID_CURVEFITTING_IDOMAINCREATOR_H_
#define MANTID_CURVEFITTING_IDOMAINCREATOR_H_

//----------------------------------------------------------------------
// Includes
@@ -20,10 +20,12 @@ namespace Mantid
namespace CurveFitting
{
/**
New algorithm for fitting functions. The name is temporary.
An base class for domain creators for use in Fit. Implementations create function domains
from particular workspaces.
@author Roman Tolchenov, Tessella plc
@date 06/12/2011
@date 22/03/2012
Copyright &copy; 2007-8 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
@@ -45,38 +47,39 @@ namespace Mantid
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport IFit : public API::Algorithm
class DLLExport IDomainCreator
{
public:
/// Default constructor
IFit() : API::Algorithm(),m_function() {};
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "Optimization";}

protected:
/// Sets documentation strings for this algorithm
virtual void initDocs();
// Overridden Algorithm methods
void init();
void exec();
/// Virtual destructor
virtual ~IDomainCreator() {};

/// declare properties that specify the dataset within the workspace to fit to.
virtual void declareDatasetProperties() {}
/// Create a domain from the input workspace
/// Create a domain and values from the input workspace. FunctionValues must be filled with data to fit to.
virtual void createDomain(boost::shared_ptr<API::FunctionDomain>&, boost::shared_ptr<API::FunctionValues>&) = 0;
/// Create an output workspace filled with data simulated with the fitting function
virtual void createOutputWorkspace(
const std::string& baseName,
boost::shared_ptr<API::FunctionDomain> domain,
boost::shared_ptr<API::FunctionValues> values) {}
virtual void initFunction();

/// Pointer to the fitting function
API::IFunction_sptr m_function;

protected:
/// Constructor.
/// @param fit :: Fit algorithm this creator will create domains for
IDomainCreator(API::Algorithm* fit):m_fit(fit){}
/// A friend that can create instances of this class
friend class Fit;
/// Log as the algorithm
Kernel::Logger& log() const;
/// Declare a property to the algorithm
void declareProperty(Kernel::Property* prop,const std::string& doc);
/// Pointer to the Fit algorithm
API::Algorithm* m_fit;
};


} // namespace CurveFitting
} // namespace Mantid

#endif /*MANTID_CURVEFITTING_IFIT_H_*/
#endif /*MANTID_CURVEFITTING_IDOMAINCREATOR_H_*/

Large diffs are not rendered by default.

@@ -29,23 +29,11 @@ namespace Mantid
namespace CurveFitting
{

// Register the class into the algorithm factory
DECLARE_ALGORITHM(FitMD)

/// Sets documentation strings for this algorithm
void FitMD::initDocs()
{
this->setWikiSummary("Fits a function to a MD Workspace");
this->setOptionalMessage("Fits a function to a MD Workspace");
}

/// Create a domain from the input workspace
void FitMD::createDomain(boost::shared_ptr<API::FunctionDomain>& domain, boost::shared_ptr<API::FunctionValues>& values)
{
// get the function
m_function = getProperty("Function");
// get the workspace
API::Workspace_sptr ws = getProperty("InputWorkspace");
API::Workspace_sptr ws = m_fit->getProperty("InputWorkspace");
m_IMDWorkspace = boost::dynamic_pointer_cast<API::IMDWorkspace>(ws);
if (!m_IMDWorkspace)
{
@@ -69,16 +69,6 @@ namespace
};
}

// Register the class into the algorithm factory
DECLARE_ALGORITHM(FitMW)

/// Sets documentation strings for this algorithm
void FitMW::initDocs()
{
this->setWikiSummary("Fits a function to data in a Workspace ");
this->setOptionalMessage("Fits a function to data in a Workspace");
}

using namespace Kernel;
using API::WorkspaceProperty;
using API::Workspace;
@@ -95,10 +85,10 @@ namespace
mustBePositive->setLower(0);
declareProperty(new PropertyWithValue<int>("WorkspaceIndex",0, mustBePositive),
"The Workspace Index to fit in the input workspace");
declareProperty("StartX", EMPTY_DBL(),
declareProperty(new PropertyWithValue<double>("StartX", EMPTY_DBL()),
"A value of x in, or on the low x boundary of, the first bin to include in\n"
"the fit (default lowest value of x)" );
declareProperty("EndX", EMPTY_DBL(),
declareProperty(new PropertyWithValue<double>("EndX", EMPTY_DBL()),
"A value in, or on the high x boundary of, the last bin the fitting range\n"
"(default the highest value of x)" );
}
@@ -107,21 +97,21 @@ namespace
void FitMW::createDomain(boost::shared_ptr<API::FunctionDomain>& domain, boost::shared_ptr<API::FunctionValues>& values)
{
// get the function
m_function = getProperty("Function");
m_function = m_fit->getProperty("Function");
// get the workspace
API::Workspace_sptr ws = getProperty("InputWorkspace");
API::Workspace_sptr ws = m_fit->getProperty("InputWorkspace");
m_matrixWorkspace = boost::dynamic_pointer_cast<API::MatrixWorkspace>(ws);
if (!m_matrixWorkspace)
{
throw std::invalid_argument("InputWorkspace must be a MatrixWorkspace.");
}
//m_function->setWorkspace(ws);
int index = getProperty("WorkspaceIndex");
int index = m_fit->getProperty("WorkspaceIndex");
m_workspaceIndex = static_cast<size_t>(index);

const Mantid::MantidVec& X = m_matrixWorkspace->readX(m_workspaceIndex);
double startX = getProperty("StartX");
double endX = getProperty("EndX");
double startX = m_fit->getProperty("StartX");
double endX = m_fit->getProperty("EndX");

if (X.empty())
{
@@ -229,7 +219,7 @@ namespace

if (foundZeroOrNegativeError)
{
g_log.warning() << "Zero or negative errors are replaced with 1.0\n";
log().warning() << "Zero or negative errors are replaced with 1.0\n";
}

}
@@ -312,9 +302,8 @@ namespace

declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace","",Direction::Output),
"Name of the output Workspace holding resulting simulated spectrum");
setPropertyValue("OutputWorkspace",baseName+"Workspace");

setProperty("OutputWorkspace",ws);
m_fit->setPropertyValue("OutputWorkspace",baseName+"Workspace");
m_fit->setProperty("OutputWorkspace",ws);

}

@@ -0,0 +1,46 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidCurveFitting/IDomainCreator.h"
#include "MantidCurveFitting/Fit.h"

namespace Mantid
{
namespace CurveFitting
{

Kernel::Logger& IDomainCreator::log() const
{
return static_cast<Fit*>(m_fit)->g_log;
}

/**
* Declare a property to the algorithm.
* @param prop :: A new property.
* @param doc :: A doc string.
*/
void IDomainCreator::declareProperty(Kernel::Property* prop,const std::string& doc)
{
static_cast<Fit*>(m_fit)->declareProperty(prop,doc);
}

/**
* Initialize the function with the workspace. Default is to call IFunction::setWorkspace().
*/
void IDomainCreator::initFunction()
{
API::IFunction_sptr function = m_fit->getProperty("Function");
if (!function)
{
throw std::runtime_error("Cannot initialize empty function.");
}
API::Workspace_sptr workspace = m_fit->getProperty("InputWorkspace");
if (!workspace)
{
throw std::runtime_error("Cannot initialize function: workspace undefined.");
}
function->setWorkspace(workspace);
}

} // namespace Algorithm
} // namespace Mantid

This file was deleted.

Large diffs are not rendered by default.

@@ -214,12 +214,12 @@ namespace Mantid
try
{
// Fit the function
API::IAlgorithm_sptr fit = createSubAlgorithm("FitMW");
API::IAlgorithm_sptr fit = createSubAlgorithm("Fit");
fit->initialize();
fit->setPropertyValue("Function",fun);
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"));
@@ -5,7 +5,7 @@

#include "MantidCurveFitting/BackToBackExponential.h"
#include "MantidCurveFitting/LinearBackground.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidAPI/CompositeFunction.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidAPI/AnalysisDataService.h"
@@ -179,7 +179,7 @@ class BackToBackExponentialTest : public CxxTest::TestSuite

void testAgainstMockData()
{
FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -199,9 +199,6 @@ class BackToBackExponentialTest : public CxxTest::TestSuite



alg2.setPropertyValue("InputWorkspace",wsName);
alg2.setPropertyValue("WorkspaceIndex","0");

// create function you want to fit against
CompositeFunction_sptr fnWithBk( new CompositeFunction );

@@ -230,6 +227,8 @@ class BackToBackExponentialTest : public CxxTest::TestSuite
fnWithBk.addFunction(bk);

alg2.setProperty("Function",boost::dynamic_pointer_cast<IFunction>(fnWithBk));
alg2.setPropertyValue("InputWorkspace",wsName);
alg2.setPropertyValue("WorkspaceIndex","0");

// execute fit
TS_ASSERT_THROWS_NOTHING(
@@ -4,7 +4,7 @@
#include <cxxtest/TestSuite.h>

#include "MantidCurveFitting/Chebyshev.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidAPI/FunctionFactory.h"
#include "MantidAPI/AnalysisDataService.h"
@@ -59,15 +59,16 @@ class ChebyshevTest : public CxxTest::TestSuite

AnalysisDataService::Instance().add("ChebyshevTest_ws",ws);

FitMW fit;
Chebyshev cheb;
cheb.setAttributeValue("n",3);

Fit fit;
fit.initialize();

fit.setPropertyValue("Function",cheb.asString());
fit.setPropertyValue("InputWorkspace","ChebyshevTest_ws");
fit.setPropertyValue("WorkspaceIndex","0");

Chebyshev cheb;
cheb.setAttributeValue("n",3);
fit.setPropertyValue("Function",cheb.asString());

fit.execute();
IFunction::Attribute StartX = cheb.getAttribute("StartX");
@@ -5,7 +5,7 @@

#include "MantidAPI/IPeakFunction.h"
#include "MantidAPI/CompositeFunction.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidAPI/TableRow.h"
@@ -190,13 +190,13 @@ class CompositeFunctionTest : public CxxTest::TestSuite

IFunction_sptr out;

FitMW alg;
Fit alg;
alg.initialize();

alg.setProperty("Function",boost::dynamic_pointer_cast<IFunction>(mfun));
alg.setPropertyValue("InputWorkspace","mfun");
alg.setPropertyValue("WorkspaceIndex","0");
alg.setProperty("CreateOutput",true);
alg.setProperty("Function",boost::dynamic_pointer_cast<IFunction>(mfun));
TS_ASSERT_THROWS_NOTHING(alg.execute());
TS_ASSERT(alg.isExecuted());
WS_type outWS = getWS("mfun_Workspace");
@@ -6,7 +6,7 @@
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidCurveFitting/Convolution.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidAPI/IPeakFunction.h"
@@ -341,7 +341,7 @@ class ConvolutionTest : public CxxTest::TestSuite

void testFit()
{
FitMW fit;
Fit fit;
WS_type ws = mkWS(ConvolutionExp(),1,10,24,0.13);
}

@@ -7,7 +7,7 @@
#include "MantidAPI/CompositeFunction.h"
#include "MantidCurveFitting/LinearBackground.h"
#include "MantidCurveFitting/BoundaryConstraint.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidDataObjects/Workspace2D.h"
@@ -55,7 +55,7 @@ class ExpDecayMuonTest : public CxxTest::TestSuite

void testAgainstMockData()
{
FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -4,7 +4,7 @@
#include <cxxtest/TestSuite.h>

#include "MantidCurveFitting/ExpDecayOsc.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidCurveFitting/BoundaryConstraint.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/WorkspaceFactory.h"
@@ -54,7 +54,7 @@ class ExpDecayOscTest : public CxxTest::TestSuite

void testAgainstMockData()
{
FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -7,7 +7,7 @@
#include "MantidAPI/CompositeFunction.h"
#include "MantidCurveFitting/LinearBackground.h"
#include "MantidCurveFitting/BoundaryConstraint.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/WorkspaceFactory.h"
@@ -60,7 +60,7 @@ class ExpDecayTest : public CxxTest::TestSuite

void testAgainstMockData()
{
FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -4,7 +4,7 @@
#include <cxxtest/TestSuite.h>
#include "MantidTestHelpers/FakeObjects.h"

#include "MantidCurveFitting/FitMD.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidCurveFitting/UserFunctionMD.h"

#include "MantidAPI/FrameworkManager.h"
@@ -147,7 +147,7 @@ class FitMDTest : public CxxTest::TestSuite
fun->setParameter("s",1.0);

//system("pause");
FitMD fit;
Fit fit;
fit.initialize();

fit.setProperty("InputWorkspace",ws2);
@@ -4,7 +4,7 @@
#include <cxxtest/TestSuite.h>
#include "MantidTestHelpers/FakeObjects.h"

#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidCurveFitting/UserFunction.h"
#include "MantidCurveFitting/ExpDecay.h"

@@ -51,12 +51,12 @@ class FitMWTest : public CxxTest::TestSuite
fun->setParameter("Height",1.);
fun->setParameter("Lifetime",1.0);

FitMW fit;
Fit fit;
fit.initialize();

fit.setProperty("Function",fun);
fit.setProperty("InputWorkspace",ws2);
fit.setProperty("WorkspaceIndex",0);
fit.setProperty("Function",fun);
fit.setProperty("CreateOutput",true);

fit.execute();
@@ -133,12 +133,12 @@ class FitMWTest : public CxxTest::TestSuite
API::AnalysisDataService::Instance().clear();
//--------------------------------------------------//

FitMW fit1;
Fit fit1;
fit1.initialize();

fit1.setProperty("Function",fun);
fit1.setProperty("InputWorkspace",ws2);
fit1.setProperty("WorkspaceIndex",1);
fit1.setProperty("Function",fun);

fit1.execute();

@@ -171,12 +171,12 @@ class FitMWTest : public CxxTest::TestSuite
fun->setParameter("Height",1.);
fun->setParameter("Lifetime",1.);

FitMW fit;
Fit fit;
fit.initialize();

fit.setProperty("Function",fun);
fit.setProperty("InputWorkspace",ws2);
fit.setProperty("WorkspaceIndex",0);
fit.setProperty("Function",fun);

fit.execute();

@@ -185,12 +185,12 @@ class FitMWTest : public CxxTest::TestSuite
TS_ASSERT_DELTA( fun->getParameter("Height"), 10.0, 1e-3);
TS_ASSERT_DELTA( fun->getParameter("Lifetime"), 0.5, 1e-4);

FitMW fit1;
Fit fit1;
fit1.initialize();

fit1.setProperty("Function",fun);
fit1.setProperty("InputWorkspace",ws2);
fit1.setProperty("WorkspaceIndex",1);
fit1.setProperty("Function",fun);

fit1.execute();

@@ -7,7 +7,7 @@
#include "MantidAPI/CompositeFunction.h"
#include "MantidCurveFitting/LinearBackground.h"
#include "MantidCurveFitting/BoundaryConstraint.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/WorkspaceFactory.h"
@@ -60,7 +60,7 @@ class GausDecayTest : public CxxTest::TestSuite

void testAgainstMockData()
{
FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -4,7 +4,7 @@
#include <cxxtest/TestSuite.h>

#include "MantidCurveFitting/Gaussian.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidAPI/CompositeFunction.h"
#include "MantidCurveFitting/LinearBackground.h"
#include "MantidCurveFitting/BoundaryConstraint.h"
@@ -240,15 +240,10 @@ class GaussianTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D));

// Initialise algorithm
FitMW alg;
Fit alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT( alg.isInitialized() );

// Set which spectrum to fit against and initial starting values
alg.setPropertyValue("InputWorkspace", wsName);
alg.setPropertyValue("StartX","79300");
alg.setPropertyValue("EndX","79600");

// create function you want to fit against
CompositeFunction_sptr fnWithBk( new CompositeFunction() );

@@ -273,6 +268,11 @@ class GaussianTest : public CxxTest::TestSuite
fnWithBk.addFunction(fn);

alg.setProperty("Function",boost::dynamic_pointer_cast<IFunction>(fnWithBk));
// Set which spectrum to fit against and initial starting values
alg.setPropertyValue("InputWorkspace", wsName);
alg.setPropertyValue("StartX","79300");
alg.setPropertyValue("EndX","79600");


// execute fit
TS_ASSERT_THROWS_NOTHING(
@@ -313,15 +313,10 @@ class GaussianTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D));

// Initialise algorithm
FitMW alg;
Fit alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT( alg.isInitialized() );

// Set which spectrum to fit against and initial starting values
alg.setPropertyValue("InputWorkspace", wsName);
alg.setPropertyValue("StartX","79300");
alg.setPropertyValue("EndX","79600");

// create function you want to fit against
CompositeFunction_sptr fnWithBk( new CompositeFunction() );

@@ -351,6 +346,11 @@ class GaussianTest : public CxxTest::TestSuite
fnWithBk->addFunction(fn);

alg.setProperty("Function",fnWithBk);
// Set which spectrum to fit against and initial starting values
alg.setPropertyValue("InputWorkspace", wsName);
alg.setPropertyValue("StartX","79300");
alg.setPropertyValue("EndX","79600");


// execute fit
TS_ASSERT_THROWS_NOTHING(
@@ -387,7 +387,7 @@ class GaussianTest : public CxxTest::TestSuite
Mantid::MantidVec& e = ws2D->dataE(0); // error values of counts
getMockData(y, e);

FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -443,7 +443,7 @@ class GaussianTest : public CxxTest::TestSuite
//put this workspace in the data service
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D));

FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -510,15 +510,10 @@ class GaussianTest : public CxxTest::TestSuite
const std::string priorRadius = ConfigService::Instance().getString("curvefitting.peakRadius");
ConfigService::Instance().setString("curvefitting.peakRadius","5");

FitMW alg;
Fit alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT( alg.isInitialized() );

// Set which spectrum to fit against and initial starting values
alg.setPropertyValue("InputWorkspace",wsName);
alg.setPropertyValue("StartX","79300");
alg.setPropertyValue("EndX","79600");

// create function you want to fit against
CompositeFunction_sptr fnWithBk( new CompositeFunction() );

@@ -554,6 +549,11 @@ class GaussianTest : public CxxTest::TestSuite

//alg.setPropertyValue("Function",*fnWithBk);
alg.setProperty("Function",fnWithBk);

// Set which spectrum to fit against and initial starting values
alg.setPropertyValue("InputWorkspace",wsName);
alg.setPropertyValue("StartX","79300");
alg.setPropertyValue("EndX","79600");
alg.setPropertyValue("Minimizer","Simplex");

// execute fit
@@ -4,7 +4,7 @@
#include <cxxtest/TestSuite.h>

#include "MantidCurveFitting/IkedaCarpenterPV.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidAPI/CompositeFunction.h"
#include "MantidCurveFitting/LinearBackground.h"
@@ -112,7 +112,7 @@ class IkedaCarpenterPVTest : public CxxTest::TestSuite
// here tries to fit an IC peak to a Gaussian mock data peak
void testAgainstMockData()
{
FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -131,12 +131,6 @@ class IkedaCarpenterPVTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D));


// Set general Fit parameters
alg2.setPropertyValue("InputWorkspace", wsName);
alg2.setPropertyValue("WorkspaceIndex","0");
alg2.setPropertyValue("StartX","0");
alg2.setPropertyValue("EndX","150");

// set up fitting function and pass to Fit
IkedaCarpenterPV icpv;
icpv.initialize();
@@ -151,6 +145,12 @@ class IkedaCarpenterPVTest : public CxxTest::TestSuite
//icpv.tie("Gamma", "1.0");

alg2.setPropertyValue("Function",icpv.asString());
// Set general Fit parameters
alg2.setPropertyValue("InputWorkspace", wsName);
alg2.setPropertyValue("WorkspaceIndex","0");
alg2.setPropertyValue("StartX","0");
alg2.setPropertyValue("EndX","150");


// execute fit
TS_ASSERT_THROWS_NOTHING(
@@ -5,7 +5,7 @@

#include "MantidCurveFitting/LinearBackground.h"

#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/WorkspaceFactory.h"
@@ -19,7 +19,7 @@
using namespace Mantid::Kernel;
using namespace Mantid::API;
using Mantid::CurveFitting::LinearBackground;
using Mantid::CurveFitting::FitMW;
using Mantid::CurveFitting::Fit;
using namespace Mantid::DataObjects;
using namespace Mantid::DataHandling;

@@ -46,7 +46,7 @@ class LinearBackgroundTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D));


FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -7,7 +7,7 @@
#include "MantidAPI/CompositeFunction.h"
#include "MantidCurveFitting/LinearBackground.h"
#include "MantidCurveFitting/BoundaryConstraint.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/WorkspaceFactory.h"
@@ -63,7 +63,7 @@

void testAgainstMockData()
{
FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -7,7 +7,7 @@
#include "MantidAPI/CompositeFunction.h"
#include "MantidCurveFitting/LinearBackground.h"
#include "MantidCurveFitting/BoundaryConstraint.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/WorkspaceFactory.h"
@@ -78,7 +78,7 @@ class LorentzianTest : public CxxTest::TestSuite

void testAgainstMockDataConstBackground()
{
FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -152,7 +152,7 @@ class LorentzianTest : public CxxTest::TestSuite

void testAgainstMockDataWithConstraint()
{
FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -215,7 +215,7 @@ class LorentzianTest : public CxxTest::TestSuite

void testAgainstMockDataWithConstraintAndConstBackground()
{
FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -6,7 +6,7 @@
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidCurveFitting/ProductFunction.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidCurveFitting/Gaussian.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/TableWorkspace.h"
@@ -289,10 +289,8 @@ class ProductFunctionTest : public CxxTest::TestSuite

AnalysisDataService::Instance().add(wsName,ws);

FitMW fit;
Fit fit;
fit.initialize();
fit.setPropertyValue("InputWorkspace",wsName);
fit.setPropertyValue("WorkspaceIndex","0");

f0->tie("PeakCentre","1.0");
f0->tie("Height","3.0");
@@ -301,6 +299,8 @@ class ProductFunctionTest : public CxxTest::TestSuite
f1->setParameter("Height",h2+5.0);
f1->tie("Sigma","0.5");
fit.setPropertyValue("Function",prodF.asString());
fit.setPropertyValue("InputWorkspace",wsName);
fit.setPropertyValue("WorkspaceIndex","0");

// execute fit
TS_ASSERT_THROWS_NOTHING(
@@ -5,7 +5,7 @@

#include "MantidCurveFitting/Quadratic.h"

#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/WorkspaceFactory.h"
@@ -19,7 +19,7 @@
using namespace Mantid::Kernel;
using namespace Mantid::API;
using Mantid::CurveFitting::Quadratic;
using Mantid::CurveFitting::FitMW;
using Mantid::CurveFitting::Fit;
using namespace Mantid::DataObjects;
using namespace Mantid::DataHandling;

@@ -48,7 +48,7 @@ class QuadraticTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D));


FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -4,7 +4,7 @@
#include <cxxtest/TestSuite.h>

#include "MantidCurveFitting/Resolution.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidCurveFitting/Convolution.h"
#include "MantidAPI/IPeakFunction.h"
#include "MantidAPI/FunctionFactory.h"
@@ -193,11 +193,11 @@ void tearDown()
conv.addFunction(res);
conv.addFunction(gauss);

FitMW fit;
Fit fit;
fit.initialize();
fit.setPropertyValue("Function",conv.asString());
fit.setPropertyValue("InputWorkspace","ResolutionTest_WS");
fit.setPropertyValue("WorkspaceIndex","0");
fit.setPropertyValue("Function",conv.asString());
fit.execute();

}
@@ -7,7 +7,7 @@
#include "MantidAPI/CompositeFunction.h"
#include "MantidCurveFitting/LinearBackground.h"
#include "MantidCurveFitting/BoundaryConstraint.h"
#include "MantidCurveFitting/FitMW.h"
#include "MantidCurveFitting/Fit.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/WorkspaceFactory.h"
@@ -63,7 +63,7 @@

void testAgainstMockData()
{
FitMW alg2;
Fit alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize());
TS_ASSERT( alg2.isInitialized() );

@@ -96,7 +96,9 @@ class MANTID_KERNEL_DLL IPropertyManager
template <typename T>
IPropertyManager* setProperty(const std::string &name, const T & value)
{
return setTypedProperty(name, value, boost::is_convertible<T, boost::shared_ptr<DataItem> >());
setTypedProperty(name, value, boost::is_convertible<T, boost::shared_ptr<DataItem> >());
this->afterPropertySet(name);
return this;
}

/** Specialised version of setProperty template method to handle const char *
@@ -263,6 +265,9 @@ class MANTID_KERNEL_DLL IPropertyManager
virtual void removeProperty(const std::string &name, const bool delproperty=true) = 0;
/// Clears all properties under management
virtual void clear() = 0;
/// Override this method to perform a custom action right after a property was set.
/// The argument is the property name. Default - do nothing.
virtual void afterPropertySet(const std::string&) {}

/// Utility class that enables the getProperty() method to effectively be templated on the return type
struct MANTID_KERNEL_DLL TypedValue
@@ -87,6 +87,9 @@ class MANTID_KERNEL_DLL PropertyManagerOwner: virtual public IPropertyManager
void removeProperty(const std::string &name, const bool delproperty);
/// Clears all properties under management
void clear();
/// Override this method to perform a custom action right after a property was set.
/// The argument is the property name. Default - do nothing.
virtual void afterPropertySet(const std::string&);

public:

@@ -278,6 +278,7 @@ namespace Mantid
{
Property *p = getPointerToProperty(name); // throws NotFoundError if property not in vector
std::string errorMsg = p->setValue(value);
this->afterPropertySet(name);
if ( !errorMsg.empty() )
{
errorMsg = "Invalid value for property " + p->name() + " (" +p->type() + ") \"" + value
@@ -298,6 +299,7 @@ namespace Mantid
{
Property *p = getPointerToPropertyOrdinal(index); // throws runtime_error if property not in vector
std::string errorMsg = p->setValue(value);
this->afterPropertySet(p->name());
if ( !errorMsg.empty() )
{
errorMsg = "Invalid value for property " + p->name() + " (" +p->type() + ") \"" + value
@@ -64,6 +64,7 @@ namespace Mantid
void PropertyManagerOwner::setPropertyValue( const std::string &name, const std::string &value )
{
m_properties->setPropertyValue( name, value );
this->afterPropertySet(name);
}

/** Set the value of a property by an index
@@ -75,6 +76,7 @@ namespace Mantid
void PropertyManagerOwner::setPropertyOrdinal( const int& index, const std::string &value )
{
m_properties->setPropertyOrdinal( index, value );
this->afterPropertySet(m_properties->getPointerToPropertyOrdinal(index)->name());
}


@@ -191,6 +193,15 @@ namespace Mantid
m_properties->clear();
}

/**
* Override this method to perform a custom action right after a property was set.
* The argument is the property name. Default - do nothing.
* @param name :: A property name.
*/
void PropertyManagerOwner::afterPropertySet(const std::string& name)
{
m_properties->afterPropertySet(name);
}

} // namespace Kernel
} // namespace Mantid
@@ -0,0 +1,220 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FitDialog</class>
<widget class="QWidget" name="FitDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>303</width>
<height>234</height>
</rect>
</property>
<property name="windowTitle">
<string>Fit Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="palette">
<palette>
<active>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>224</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 224);</string>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string>Fits a given function to data in one or more workspaces</string>
</property>
<property name="alignment">
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>2</number>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>283</width>
<height>189</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Function</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="leFunction"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Max iterations</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="sbMaxIterations">
<property name="maximum">
<number>1000</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Minimizer</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QComboBox" name="cbMinimizer"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Cost function</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QComboBox" name="cbCostFunction"/>
</item>
<item row="4" column="2">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Create output</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Output</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QLineEdit" name="leOutput"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -1461,19 +1461,19 @@ void FitPropertyBrowser::fit()
}
else
{
Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("FitMW");
Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("Fit");
alg->initialize();
alg->setPropertyValue("InputWorkspace",wsName);
alg->setProperty("WorkspaceIndex",workspaceIndex());
alg->setProperty("StartX",startX());
alg->setProperty("EndX",endX());
alg->setPropertyValue("Output",outputName());
alg->setPropertyValue("Function",funStr);
alg->setPropertyValue("Minimizer",minimizer());
alg->setPropertyValue("CostFunction",costFunction());
observeFinish(alg);
alg->executeAsync();
}

}
catch(std::exception& e)
{
@@ -1374,13 +1374,13 @@ void PropertyHandler::fit()
{
if (m_browser->workspaceName().empty()) return;

Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("FitMW");
Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("Fit");
alg->initialize();
alg->setProperty("Function",m_fun);
alg->setPropertyValue("InputWorkspace",m_browser->workspaceName());
alg->setProperty("WorkspaceIndex",m_browser->workspaceIndex());
alg->setProperty("StartX",m_browser->startX());
alg->setProperty("EndX",m_browser->endX());
alg->setProperty("Function",m_fun);
alg->execute();
Mantid::API::IFunction_sptr f = alg->getProperty("Function");
if (f != m_fun)