Skip to content

Commit

Permalink
refs #6865 This should fix it
Browse files Browse the repository at this point in the history
e.g. enabled explicit selection of QFrame. A but more tests is still needed.
  • Loading branch information
abuts committed Apr 23, 2013
1 parent 8a245b6 commit dc1e482
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ ConvertToMD::init()


std::vector<std::string> TargFrames = QSclAndFrames.getQScalings();
declareProperty("OutputDimensions", TargFrames[CnvrtToMD::AutoSelect],boost::make_shared<StringListValidator>(TargFrames),
declareProperty("Q3DFrames", TargFrames[CnvrtToMD::AutoSelect],boost::make_shared<StringListValidator>(TargFrames),
"What will be the Q-dimensions of the output workspace in Q3D case?\n"
" AutoSelect: Choose the target coordinate frame as the function of goniometer and UB matrix values set on the input workspace\n"
" Q (lab frame): Wave-vector change of the lattice in the lab frame.\n"
Expand Down Expand Up @@ -374,7 +374,7 @@ void ConvertToMD::exec()
//c) other dim property;
std::vector<std::string> otherDimNames = getProperty("OtherDimensions");
//d) The output dimensions in the Q3D mode, processed together with QConversionScales
std::string QFrame = getProperty("OutputDimensions");
std::string QFrame = getProperty("Q3DFrames");
//e) part of the procedure, specifying the target dimensions units. Currently only Q3D target units can be converted to different flavours of hkl
std::string convertTo_ = getProperty("QConversionScales");

Expand Down Expand Up @@ -487,7 +487,7 @@ bool ConvertToMD::buildTargetWSDescription(API::IMDEventWorkspace_sptr spws,cons
// reset new ws description name
targWSDescr =oldWSDescr;
// set up target coordinate system
targWSDescr.m_RotMatrix = MsliceProj.getTransfMatrix(targWSDescr,convertTo_);
targWSDescr.m_RotMatrix = MsliceProj.getTransfMatrix(targWSDescr,QFrame,convertTo_);
}
return createNewTargetWs;
}
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void ConvertToMDEvents::exec()

// check if we are working in powder mode
// set up target coordinate system and identify/set the (multi) dimension's names to use
TWSD.m_RotMatrix = MsliceProj.getTransfMatrix(TWSD,convert_to_);
TWSD.m_RotMatrix = MsliceProj.getTransfMatrix(TWSD,"AutoSelect",convert_to_);

}
else // user input is mainly ignored and everything is in old workspac
Expand All @@ -275,7 +275,7 @@ void ConvertToMDEvents::exec()
// reset new ws description name
TWSD = OLDWSD;
// set up target coordinate system
TWSD.m_RotMatrix = MsliceProj.getTransfMatrix(TWSD,convert_to_);
TWSD.m_RotMatrix = MsliceProj.getTransfMatrix(TWSD,"AutoSelect",convert_to_);
}

// Check what to do with detectors:
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void testInit(){
TS_ASSERT_THROWS_NOTHING( pAlg->initialize() )
TS_ASSERT( pAlg->isInitialized() )

TSM_ASSERT_EQUALS("algortithm should have 19 propeties",19,(size_t)(pAlg->getProperties().size()));
TSM_ASSERT_EQUALS("algortithm should have 20 propeties",20,(size_t)(pAlg->getProperties().size()));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class DLLExport MDWSTransform
* sets default values u and v to [1,0,0] and [0,1,0] if not present or any error. */
void setUVvectors(const std::vector<double> &ut,const std::vector<double> &vt,const std::vector<double> &wt);

std::vector<double> getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,const std::string &FrameRequested, std::string &QScaleRequested)const;
std::vector<double> getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,const std::string &FrameRequested,const std::string &QScaleRequested)const;

/// construct meaningful dimension names for Q3D case and different transformation types defined by the class
void setQ3DDimensionsNames(MDEvents::MDWSDescription &TargWSDescription,const std::string &QScaleRequested)const;
Expand Down
15 changes: 11 additions & 4 deletions Code/Mantid/Framework/MDEvents/src/MDWSTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ namespace MDEvents
Kernel::Logger& MDWSTransform::g_Log =Kernel::Logger::get("MD-Algorithms");
using namespace CnvrtToMD;

/** method returns the linear representation for the transformation matrix, which translate momentums from laboratory to the requested
* coordinate system.
/** method to build the Q-coordinates transfomration.
*
* depending on the presence of UB matrix and goniometer settings, it may be:
* @param TargWSDescription -- the class which describes target MD workspace. In Q3D case this descritpion is modifiede by the method
with default Q-axis labels and Q-axis untis
* @param FrameRequested -- the string which describes the target transformation frame in Q3D case. If the string value is '''Auto'''
* the frame is selected depending on the presence of UB matrix and goniometer settings, namely it can be:
* a) the laboratory -- (no UB matrix, goniometer angles set to 0)
b) Q (sample frame)''': the goniometer rotation of the sample is taken out, to give Q in the frame of the sample. See [[SetGoniometer]] to specify the goniometer used in the experiment.
c) Crystal or crystal cartezian (C)- Busing, Levi 1967 coordinate system -- depenging on Q-scale requested
* one of the target frames above can be requested explicitly. In this case the method throws invalid argument if necessary parameters (UB matrix) is not attached to the workspace
* @param QScaleRequested -- Q-transformation needed
*
* @return the linear representation for the transformation matrix, which translate momentums from laboratory to the requested
* coordinate system.
*/
std::vector<double> MDWSTransform::getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,const std::string &FrameRequested,std::string &QScaleRequested)const
std::vector<double> MDWSTransform::getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,const std::string &FrameRequested,const std::string &QScaleRequested)const
{
CoordScaling ScaleID = getQScaling(QScaleRequested);
TargetFrame FrameID = getTargetFrame(FrameRequested);
Expand Down
41 changes: 32 additions & 9 deletions Code/Mantid/Framework/MDEvents/test/MDWSTransfTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ using namespace Mantid::Kernel;
class MDWSTransformTestHelper: public MDWSTransform
{
public:
std::vector<double> getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,CnvrtToMD::CoordScaling &scaling)const
std::vector<double> getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,CnvrtToMD::TargetFrame frames,CnvrtToMD::CoordScaling scaling)const
{
return MDWSTransform::getTransfMatrix(TargWSDescription,scaling);
CnvrtToMD::CoordScaling inScaling(scaling);
return MDWSTransform::getTransfMatrix(TargWSDescription,frames,inScaling);
}
CnvrtToMD::TargetFrame findTargetFrame(MDEvents::MDWSDescription &TargWSDescription)const
{
Expand Down Expand Up @@ -66,6 +67,28 @@ void testFindTargetFrame()
TS_ASSERT_EQUALS(CnvrtToMD::HKLFrame,Transf.findTargetFrame(TargWSDescription));

}
void testForceTargetFrame()
{
MDEvents::MDWSDescription TargWSDescription;
Mantid::API::MatrixWorkspace_sptr spws =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(4,10,true);
std::vector<double> minVal(4,-3),maxVal(4,3);
TargWSDescription.setMinMax(minVal,maxVal);

TargWSDescription.buildFromMatrixWS(spws,"Q3D","Direct");

MDWSTransformTestHelper Transf;
TS_ASSERT_THROWS(Transf.getTransfMatrix(TargWSDescription,CnvrtToMD::HKLFrame,CnvrtToMD::HKLScale),std::invalid_argument);
TS_ASSERT_THROWS(Transf.getTransfMatrix(TargWSDescription,CnvrtToMD::SampleFrame,CnvrtToMD::HKLScale),std::invalid_argument);
spws->mutableSample().setOrientedLattice(new Geometry::OrientedLattice(*pLattice));
spws->mutableRun().mutableGoniometer().setRotationAngle(0,20);

std::vector<double> transf;
TS_ASSERT_THROWS_NOTHING(transf=Transf.getTransfMatrix(TargWSDescription,CnvrtToMD::SampleFrame,CnvrtToMD::HKLScale));


}



void test_buildDimNames(){

Expand Down Expand Up @@ -124,7 +147,7 @@ void testTransfMat1()

ws2D->mutableRun().mutableGoniometer().setRotationAngle(0,0);
CnvrtToMD::CoordScaling scales = CnvrtToMD::HKLScale;
TS_ASSERT_THROWS_NOTHING(rot=MsliceTransf.getTransfMatrix(TWS,scales));
TS_ASSERT_THROWS_NOTHING(rot=MsliceTransf.getTransfMatrix(TWS,CnvrtToMD::AutoSelect,scales));
TS_ASSERT_THROWS_NOTHING(MsliceTransf.setQ3DDimensionsNames(TWS,CnvrtToMD::HKLScale));

dimNames = TWS.getDimNames();
Expand All @@ -136,7 +159,7 @@ void testTransfMat1()

std::vector<double> rot1;
scales = CnvrtToMD::OrthogonalHKLScale;
TS_ASSERT_THROWS_NOTHING(rot1=MsliceTransf.getTransfMatrix(TWS,scales));
TS_ASSERT_THROWS_NOTHING(rot1=MsliceTransf.getTransfMatrix(TWS,CnvrtToMD::AutoSelect,scales));
TS_ASSERT_THROWS_NOTHING(MsliceTransf.setQ3DDimensionsNames(TWS,scales));

dimNames = TWS.getDimNames();
Expand All @@ -157,9 +180,9 @@ void testTransfMat1()
// Orthogonal HKL and HKL are equivalent for rectilinear lattice for any goniometer position
ws2D->mutableRun().mutableGoniometer().setRotationAngle(0,60);
scales = CnvrtToMD::HKLScale;
TS_ASSERT_THROWS_NOTHING(rot=MsliceTransf.getTransfMatrix(TWS,scales));
TS_ASSERT_THROWS_NOTHING(rot=MsliceTransf.getTransfMatrix(TWS,CnvrtToMD::AutoSelect,scales));
scales = CnvrtToMD::OrthogonalHKLScale;
TS_ASSERT_THROWS_NOTHING(rot1=MsliceTransf.getTransfMatrix(TWS,scales));
TS_ASSERT_THROWS_NOTHING(rot1=MsliceTransf.getTransfMatrix(TWS,CnvrtToMD::AutoSelect,scales));
for(int i=0;i<9;i++)
{
TSM_ASSERT_DELTA(" element: "+boost::lexical_cast<std::string>(i)+" wrong",rot[i],rot1[i],1.e-6);
Expand Down Expand Up @@ -191,7 +214,7 @@ void testTransf2HoraceQinA()

CnvrtToMD::CoordScaling scales = CnvrtToMD::NoScaling;
ws2D->mutableRun().mutableGoniometer().setRotationAngle(0,20);
TS_ASSERT_THROWS_NOTHING(rot=MsliceTransf.getTransfMatrix(TWS,scales));
TS_ASSERT_THROWS_NOTHING(rot=MsliceTransf.getTransfMatrix(TWS,CnvrtToMD::AutoSelect,scales));

// and this is Horace transformation matrix obtained from [transf,u_to_rlu]=calc_proj_matrix(alat, angldeg, u, v, 20*deg2rad, omega, dpsi, gl, gs) (private folder in sqw)
// 0.9397 0.3420 0
Expand All @@ -213,7 +236,7 @@ void testTransf2HoraceQinA()
Transf[2][0] = 0.; Transf[2][1] = 0.; Transf[2][2] = 1;

ws2D->mutableRun().mutableGoniometer().setRotationAngle(0,40);
TS_ASSERT_THROWS_NOTHING(rot=MsliceTransf.getTransfMatrix(TWS,scales));
TS_ASSERT_THROWS_NOTHING(rot=MsliceTransf.getTransfMatrix(TWS,CnvrtToMD::AutoSelect,scales));
sample = (PermHM*Transf*PermMH).getVector();
for(size_t i=0;i<9;i++)
{
Expand Down Expand Up @@ -287,7 +310,7 @@ void testTransf2HKL()
U2RLU[2][0] = 0.; U2RLU[2][1] = 0.; U2RLU[2][2] = 1.1244;

CnvrtToMD::CoordScaling scales = CnvrtToMD::HKLScale;
TS_ASSERT_THROWS_NOTHING(rot=MsliceTransf.getTransfMatrix(TWS,scales));
TS_ASSERT_THROWS_NOTHING(rot=MsliceTransf.getTransfMatrix(TWS,CnvrtToMD::AutoSelect,scales));

auto sample = U2RLU.getVector();
for(size_t i=0;i<9;i++)
Expand Down

0 comments on commit dc1e482

Please sign in to comment.