Skip to content

Commit

Permalink
Unit test that tests ApplyCalibration runs re #5797
Browse files Browse the repository at this point in the history
Also ApplyCalibration that uses Geometry::ComponentHelper::moveComponent

Signed-off-by: Karl Palmen <karl.palmen@stfc.ac.uk>
  • Loading branch information
KarlPalmen committed Mar 15, 2013
1 parent a58d83d commit 50c7203
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ set ( TEST_FILES
AlphaCalcTest.h
AnyShapeAbsorptionTest.h
AppendSpectraTest.h
ApplyCalibrationTest.h
ApplyDeadTimeCorrTest.h
ApplyDetailedBalanceTest.h
ApplyTransmissionCorrectionTest.h
Expand Down
21 changes: 17 additions & 4 deletions Code/Mantid/Framework/Algorithms/src/ApplyCalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The PositionTable must have columns ''Detector ID'' and ''Detector Position''. T
#include "MantidGeometry/Instrument/Component.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/SpectraDetectorMap.h"
#include "MantidGeometry/Instrument/ComponentHelper.h"
#include <boost/scoped_ptr.hpp>

namespace Mantid
Expand All @@ -33,7 +35,7 @@ namespace Mantid
using Geometry::Instrument;
using Geometry::Instrument_sptr;
using Geometry::IDetector_sptr;
using Kernel::V3D;
using Geometry::IComponent_const_sptr;

/// Empty default constructor
ApplyCalibration::ApplyCalibration()
Expand Down Expand Up @@ -91,7 +93,17 @@ namespace Mantid
*/
void ApplyCalibration::setDetectorPosition(const Geometry::Instrument_const_sptr & instrument, int detID, V3D pos, bool /*sameParent*/ )
{
Geometry::IDetector_const_sptr det = instrument->getDetector(detID);

IComponent_const_sptr det =instrument->getDetector(detID); ;
// Do the move
using namespace Geometry::ComponentHelper;
TransformType positionType = Absolute;
// TransformType positionType = Relative;
Geometry::ComponentHelper::moveComponent(*det, *m_pmap, pos, positionType);


/*
const Geometry::IDetector_const_sptr det = instrument->getDetector(detID);
// Then find the corresponding relative position
boost::shared_ptr<const Geometry::IComponent> parent = det->getParent();
if (parent)
Expand All @@ -100,7 +112,7 @@ namespace Mantid
Quat rot = parent->getRelativeRot();
rot.inverse();
rot.rotate(pos);
}
}
boost::shared_ptr<const Geometry::IComponent>grandparent = parent->getParent();
if (grandparent)
{
Expand All @@ -113,7 +125,8 @@ namespace Mantid
rot2.inverse();
rot2.rotate(pos);
}
}
}
*/

// Add a parameter for the new position
m_pmap->addV3D(det.get(), "pos", pos);
Expand Down
76 changes: 76 additions & 0 deletions Code/Mantid/Framework/Algorithms/test/ApplyCalibrationTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#ifndef APPLYCALIBRATIONTEST_H_
#define APPLYCALIBRATIONTEST_H_

#include <cxxtest/TestSuite.h>

#include "MantidDataHandling/LoadInstrument.h"
#include "MantidAPI/IAlgorithm.h"
#include "MantidAlgorithms/ApplyCalibration.h"
#include "MantidAPI/Workspace.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "WorkspaceCreationHelperTest.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/TableRow.h"
#include "MantidKernel/V3D.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/Component.h"
#include <stdexcept>

using namespace Mantid::Algorithms;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::DataObjects;

class ApplyCalibrationTest : public CxxTest::TestSuite
{
public:

void testName()
{
TS_ASSERT_EQUALS( appCalib.name(), "ApplyCalibration" )
}

void testInit()
{
appCalib.initialize();
TS_ASSERT( appCalib.isInitialized() )
}

void testExec()
{
// Create workspace with paremeterised instrument
Workspace2D_sptr ws = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(3, 10, true);

// Create Calibration Table
ITableWorkspace_sptr posTableWs = WorkspaceFactory::Instance().createTable();
posTableWs->addColumn("int","Detector ID");
posTableWs->addColumn("V3D","Detector Position");

for(int i=0; i < 3; ++i)
{
TableRow row = posTableWs->appendRow();
row << i << V3D(1.0,0.01*i,1.0);
}
TS_ASSERT_THROWS_NOTHING(appCalib.setProperty<Workspace2D_sptr>("Workspace", ws ));
TS_ASSERT_THROWS_NOTHING(appCalib.setProperty<ITableWorkspace_sptr>("PositionTable", posTableWs ));
try
{
TS_ASSERT_EQUALS(appCalib.execute(),true);
}
catch(std::runtime_error & e)
{
TS_FAIL(e.what());
}
TS_ASSERT( appCalib.isExecuted() );

}

private:
ApplyCalibration appCalib;


};

#endif /*APPLYCALIBRATIONTEST_H_*/

0 comments on commit 50c7203

Please sign in to comment.