Skip to content

Commit

Permalink
refs #6865 Should allow user to choose a frame of interest in Q3D mode
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Apr 22, 2013
1 parent 9040294 commit 8a245b6
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace MDAlgorithms
API::IMDEventWorkspace_sptr createNewMDWorkspace(const MDEvents::MDWSDescription &NewMDWSDescription);

bool buildTargetWSDescription(API::IMDEventWorkspace_sptr spws,const std::string &Q_mod_req,const std::string &dEModeRequested,const std::vector<std::string> &other_dim_names,
const std::string &convert_to_,MDEvents::MDWSDescription &targWSDescr);
const std::string &QFrame,const std::string &convert_to_,MDEvents::MDWSDescription &targWSDescr);
/// Store metadata
void copyMetaData(API::IMDEventWorkspace_sptr mdEventWS) const;

Expand Down
31 changes: 25 additions & 6 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,25 @@ ConvertToMD::init()
"the number of the target workspace dimensions by one. See [[MD Transformation factory]] for further details.",
Direction::InOut);

MDEvents::MDWSTransform QScl;
std::vector<std::string> QScales = QScl.getQScalings();
MDEvents::MDWSTransform QSclAndFrames;
std::vector<std::string> QScales = QSclAndFrames.getQScalings();
declareProperty("QConversionScales",QScales[CnvrtToMD::NoScaling], boost::make_shared<StringListValidator>(QScales),
"This property to normalize three momentums obtained in '''Q3D''' mode. See [[MD Transformation factory]] "
"for description and available scaling modes. The value can be modified depending on the target coordinate "
"system, defined by the property '''OutputDimensions'''. "
);


std::vector<std::string> TargFrames = QSclAndFrames.getQScalings();
declareProperty("OutputDimensions", 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"
" Q (sample frame): Wave-vector change of the lattice in the frame of the sample (taking out goniometer rotation).\n"
" HKL: Use the sample's UB matrix to convert to crystal's HKL indices.\n"
"See [[ MD_Transformation_factory#Q3D |MD Transformation factory]] for more details about this. "
);

declareProperty("QConversionScales",QScales[CnvrtToMD::NoScaling], boost::make_shared<StringListValidator>(QScales),
"This property to normalize three momentums obtained in '''Q3D''' mode. See [[MD Transformation factory]] "
"for description and available scaling modes. The value can be modified depending on the target coordinate "
Expand Down Expand Up @@ -356,13 +373,15 @@ void ConvertToMD::exec()
std::string dEModReq = getProperty("dEAnalysisMode");
//c) other dim property;
std::vector<std::string> otherDimNames = getProperty("OtherDimensions");
//d) part of the procedure, specifying the target dimensions units. Currently only Q3D target units can be converted to different flavours of hkl
//d) The output dimensions in the Q3D mode, processed together with QConversionScales
std::string QFrame = getProperty("OutputDimensions");
//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");

// Build the target ws description as function of the input & output ws and the parameters, supplied to the algorithm
MDEvents::MDWSDescription targWSDescr;
// get workspace parameters and build target workspace descritpion, report if there is need to build new target MD workspace
bool createNewTargetWs = buildTargetWSDescription(spws,QModReq,dEModReq,otherDimNames,convertTo_,targWSDescr);
bool createNewTargetWs = buildTargetWSDescription(spws,QModReq,dEModReq,otherDimNames,QFrame,convertTo_,targWSDescr);

// create and initate new workspace or set up existing workspace as a target.
if(createNewTargetWs) // create new
Expand Down Expand Up @@ -420,7 +439,7 @@ ConvertToMD::ConvertToMD()
{}
/** handle the input parameters and build target workspace description as function of input parameters */
bool ConvertToMD::buildTargetWSDescription(API::IMDEventWorkspace_sptr spws,const std::string &QModReq,const std::string &dEModReq,const std::vector<std::string> &otherDimNames,
const std::string &convertTo_,MDEvents::MDWSDescription &targWSDescr)
const std::string &QFrame,const std::string &convertTo_,MDEvents::MDWSDescription &targWSDescr)
{
// ------- Is there need to creeate new ouptutworpaced?
bool createNewTargetWs =doWeNeedNewTargetWorkspace(spws);
Expand Down Expand Up @@ -452,7 +471,7 @@ bool ConvertToMD::buildTargetWSDescription(API::IMDEventWorkspace_sptr spws,cons

// check if we are working in powder mode
// set up target coordinate system and identify/set the (multi) dimension's names to use
targWSDescr.m_RotMatrix = MsliceProj.getTransfMatrix(targWSDescr,convertTo_);
targWSDescr.m_RotMatrix = MsliceProj.getTransfMatrix(targWSDescr,QFrame,convertTo_);
}
else // user input is mainly ignored and everything is in old MD workspace
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ namespace CnvrtToMD
LabFrame, //< * '''Q (lab frame)''': this calculates the momentum transfer (ki-kf) for each event is calculated in the experimental lab frame.
SampleFrame, //< * '''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.
HKLFrame, //<* '''HKL''': uses the UB matrix (see [[SetUB]], [[FindUBUsingFFT]] and others) to calculate the HKL Miller indices of each event.
Auto //<* This tries to select one of above by analyzing the goniometer and UB matrix parameters on the workspace and tries to establish what coordinate system is actually defined/needed.
AutoSelect, //<* This tries to select one of above by analyzing the goniometer and UB matrix parameters on the workspace and tries to establish what coordinate system is actually defined/needed.
NTargetFrames
};
}

Expand All @@ -70,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 &QScaleRequested)const;
std::vector<double> getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,const std::string &FrameRequested, 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 All @@ -81,7 +82,7 @@ class DLLExport MDWSTransform
std::vector<std::string> getQScalings()const{return m_QScalingID;}
CnvrtToMD::CoordScaling getQScaling(const std::string &ScID)const;
/// returns the list of possible target frames to convert to
std::vector<std::string> getTargetFrames()const;
std::vector<std::string> getTargetFrames()const{return m_TargFramesID;}
/// converts the target frame string representation into the frame ID
CnvrtToMD::TargetFrame getTargetFrame(const std::string &FrameID)const;
private:
Expand All @@ -95,17 +96,20 @@ class DLLExport MDWSTransform

/// string representation of QScaling ID, which would be known to user
std::vector<std::string> m_QScalingID;
//
/// string representation of Target frames, which would be exposed to user;
std::vector<std::string> m_TargFramesID;
bool v3DIsDefault(const std::vector<double> &vect,const std::string &message)const;
protected: // for testing
/// function generates "Kind of" W transformation matrix for different Q-conversion modes;
Kernel::DblMatrix buildQTrahsf(MDEvents::MDWSDescription &TargWSDescription,CnvrtToMD::CoordScaling scaling,bool UnitUB=false)const;
/// build orthogonal coordinate around two input vecotors u and v expressed in rlu;
//std::vector<Kernel::V3D> buildOrtho3D(const Kernel::DblMatrix &BM,const Kernel::V3D &u, const Kernel::V3D &v)const;

std::vector<double> getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,CnvrtToMD::CoordScaling &scaling)const;
std::vector<double> getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,CnvrtToMD::TargetFrame FrameID,CnvrtToMD::CoordScaling &scaling)const;

CnvrtToMD::TargetFrame findTargetFrame(MDEvents::MDWSDescription &TargWSDescription)const;
// helper function which verifies, if the input information availble on the workspace consistent with the frame requiested
void checkTargetFrame(const MDEvents::MDWSDescription &TargWSDescription,const CnvrtToMD::TargetFrame CoordFrameID)const;

};

Expand Down
54 changes: 49 additions & 5 deletions Code/Mantid/Framework/MDEvents/src/MDWSTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ using namespace CnvrtToMD;
c) Crystal or crystal cartezian (C)- Busing, Levi 1967 coordinate system -- depenging on Q-scale requested
*/
std::vector<double> MDWSTransform::getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,const std::string &QScaleRequested)const
std::vector<double> MDWSTransform::getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,const std::string &FrameRequested,std::string &QScaleRequested)const
{
CoordScaling ScaleID = getQScaling(QScaleRequested);
std::vector<double> transf = getTransfMatrix(TargWSDescription,ScaleID);
TargetFrame FrameID = getTargetFrame(FrameRequested);
std::vector<double> transf = getTransfMatrix(TargWSDescription,FrameID,ScaleID);

if(TargWSDescription.AlgID.compare("Q3D")==0)
{
Expand Down Expand Up @@ -58,10 +59,31 @@ CnvrtToMD::TargetFrame MDWSTransform::findTargetFrame(MDEvents::MDWSDescription
if(!isLatticeUnitMat)return HKLFrame;
return SampleFrame;
}
/** Method verifies if the information availible on the source workspace is sufficient to build appropriate frame
*@param TargWSDescription -- the class which contains the information about the target workspace
*@param CoordFrameID -- the ID of the target frame requested
*
* method throws invalid argument if the infomration on the workspace is insufficient to define the frame requested
*/
void MDWSTransform::checkTargetFrame(const MDEvents::MDWSDescription &TargWSDescription,const CnvrtToMD::TargetFrame CoordFrameID)const
{
switch(CoordFrameID)
{
case(LabFrame): // nothing needed for lab frame
return;
case(SampleFrame):
case(HKLFrame): // ubMatrix has to be present
if(!TargWSDescription.hasLattice())
throw std::invalid_argument(" Target frame and sample frame need defined UB matrix ");
default:
throw std::runtime_error(" Unexpected argument in MDWSTransform::checkTargetFrame");
}

}


/** The matrix to convert neutron momentums into the target coordinate system */
std::vector<double> MDWSTransform::getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,CoordScaling &ScaleID)const
std::vector<double> MDWSTransform::getTransfMatrix(MDEvents::MDWSDescription &TargWSDescription,CnvrtToMD::TargetFrame FrameID,CoordScaling &ScaleID)const
{

Kernel::Matrix<double> mat(3,3,true);
Expand All @@ -80,7 +102,13 @@ std::vector<double> MDWSTransform::getTransfMatrix(MDEvents::MDWSDescription &Ta
" as no oriented lattice has been defined. \n"
" Will use unit transformation matrix\n";
}
CnvrtToMD::TargetFrame CoordFrameID = findTargetFrame(TargWSDescription);
// set the frame ID to the values, requested by properties
CnvrtToMD::TargetFrame CoordFrameID(FrameID);
if(FrameID==AutoSelect) // if this value is autoselect, find appropriate frame from workspace properties
CoordFrameID = findTargetFrame(TargWSDescription);
else // if not, and specific target frame requested, veirfy if everything is availible on the workspace for this frame
checkTargetFrame(TargWSDescription,CoordFrameID); // throw, if the information is not availible

switch(CoordFrameID)
{
case(CnvrtToMD::LabFrame):
Expand Down Expand Up @@ -369,10 +397,21 @@ CoordScaling MDWSTransform::getQScaling(const std::string &ScID)const
return CoordScaling(nScaling);
}

/** function which convert input string representing Target coordinate frame to correspondent enum */
TargetFrame MDWSTransform::getTargetFrame(const std::string &FrameID)const
{
int nFrame = Kernel::Strings::isMember(m_TargFramesID,FrameID);

if (nFrame<0)throw(std::invalid_argument(" The Target Frame with ID: "+FrameID+" is unavalible"));

return TargetFrame(nFrame);
}

//
MDWSTransform::MDWSTransform():
m_isUVdefault(true),
m_QScalingID(NCoordScalings)
m_QScalingID(NCoordScalings),
m_TargFramesID(NTargetFrames)
{
m_UProj[0] = 1; m_UProj[1] = 0; m_UProj[2] = 0;
m_VProj[0] = 0; m_VProj[1] = 1; m_VProj[2] = 0;
Expand All @@ -384,6 +423,11 @@ MDWSTransform::MDWSTransform():
m_QScalingID[OrthogonalHKLScale]="Orthogonal HKL";
m_QScalingID[HKLScale]="HKL";

m_TargFramesID[AutoSelect]="AutoSelect";
m_TargFramesID[LabFrame]="Q (lab frame)";
m_TargFramesID[SampleFrame]="Q (sample frame)";
m_TargFramesID[HKLFrame]="HKL";

}

}
Expand Down

0 comments on commit 8a245b6

Please sign in to comment.