Skip to content

Commit

Permalink
Added the unit test. Re #7572.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Aug 1, 2013
1 parent a1377b1 commit 39c747b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
46 changes: 46 additions & 0 deletions Code/Mantid/Framework/CurveFitting/test/FitMWTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "MantidAPI/WorkspaceProperty.h"

#include "MantidKernel/PropertyManager.h"
#include "MantidGeometry/Instrument.h"

#include <sstream>

Expand Down Expand Up @@ -438,6 +439,51 @@ class FitMWTest : public CxxTest::TestSuite

}

void test_setting_instrument_fitting_parameters()
{
boost::shared_ptr<Mantid::Geometry::Instrument> instrument;
instrument.reset(new Mantid::Geometry::Instrument);
Mantid::Geometry::ObjComponent *source = new Mantid::Geometry::ObjComponent("source");
source->setPos(0.0,0.0,-10.0);
instrument->markAsSource(source);
Mantid::Geometry::ObjComponent *sample = new Mantid::Geometry::ObjComponent("sample");
instrument->markAsSamplePos(sample);
boost::shared_ptr<Mantid::Geometry::Detector> det = boost::shared_ptr<Mantid::Geometry::Detector>(new Mantid::Geometry::Detector("det",1,0));
instrument->markAsDetector(det.get());

API::MatrixWorkspace_sptr ws = createTestWorkspace(false);
ws->setInstrument( instrument );
ws->getSpectrum(0)->setDetectorID(det->getID());

auto &pmap = ws->instrumentParameters();

std::string value = "20.0 , ExpDecay , Lifetime , , , , , , , TOF ,";
pmap.add("fitting",det.get(), "Lifetime", value);
boost::shared_ptr<const Mantid::Geometry::IDetector> pdet = instrument->getDetector(det->getID());
TS_ASSERT( pdet );

Geometry::Parameter_sptr param = pmap.getRecursive(pdet.get(), "Lifetime", "fitting");
TS_ASSERT( param );

API::IFunction_sptr expDecay(new ExpDecay);
FunctionDomain_sptr domain;
IFunctionValues_sptr values;

// Requires a property manager to make a workspce
auto propManager = boost::make_shared<Mantid::Kernel::PropertyManager>();
const std::string wsPropName = "TestWorkspaceInput";
propManager->declareProperty(new WorkspaceProperty<Workspace>(wsPropName, "", Mantid::Kernel::Direction::Input));
propManager->setProperty<Workspace_sptr>(wsPropName, ws);

FitMW fitmw( propManager.get(), wsPropName);
fitmw.declareDatasetProperties("", true);
fitmw.createDomain(domain, values);
fitmw.initFunction(expDecay);

// test that the Lifetime parameter value was picked up from the instrument parameter map
TS_ASSERT_EQUALS( expDecay->getParameter("Lifetime"), 20.0 );
}

private:

API::MatrixWorkspace_sptr createTestWorkspace(const bool histogram)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ namespace Geometry
void clearParametersByName(const std::string & name);

/// Method for adding a parameter providing its value as a string
void add(const std::string& type,const IComponent* comp,const std::string& name,
void add(const std::string& type,const IComponent* comp,const std::string& name,
const std::string& value);

// /// Method for adding a parameter providing its value as a char string
// void add(const std::string& type,const IComponent* comp,const std::string& name,
// const char* value) {add( type, comp, name, std::string(value));}

/**
* Method for adding a parameter providing its value of a particular type
* @tparam T The concrete type
Expand Down

0 comments on commit 39c747b

Please sign in to comment.