Skip to content

Commit

Permalink
refs #6856 All works except single event per bin
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed May 24, 2013
1 parent b8f384b commit 6354c94
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace MDAlgorithms
// method to convert the value of the target frame specified for the ConvertToDiffractionMDWorksapce into the properties names of the ConvertToMD
void convertFramePropertyNames(const std::string &ConvToDifrWSPropName,std::string &TargFrameName,std::string & ScalingName);
// method to convert the extents specified for the ConvertToDiffractionMDWorksapce into the min-max properties names of the ConvertToMD
void convertExtents(const std::string &Extents,std::string &minVal,std::string &maxVal);
void convertExtents(const std::vector<double> &Extents,std::vector<double> &minVal,std::vector<double> &maxVal)const;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace MDAlgorithms

}

void ConvertToDiffractionMDWorkspace2::convertExtents(const std::string &Extents,std::string &minVal,std::string &maxVal)
void ConvertToDiffractionMDWorkspace2::convertExtents(const std::vector<double> &Extents,std::vector<double> &minVal,std::vector<double> &maxVal)const
{
minVal.resize(3);
maxVal.resize(3);
Expand Down Expand Up @@ -243,10 +243,10 @@ namespace MDAlgorithms

Convert->setRethrows(true);
Convert->initialize();
API::MatrixWorkspace_const_sptr inWS = getProperty("InputWorkspace");
std::string inWSName = this->getPropertyValue("InputWorkspace");
std::string outWSName = this->getPropertyValue("OutputWorkspace");

Convert->setProperty("InputWorkspace",inWS);
Convert->setProperty("InputWorkspace",inWSName);
Convert->setProperty("OutputWorkspace",outWSName);
Convert->setProperty("OverwriteExisting",!this->getProperty("Append"));

Expand All @@ -271,8 +271,9 @@ namespace MDAlgorithms
bool lorCorr = this->getProperty("LorentzCorrection");
Convert->setProperty("LorentzCorrection",lorCorr);
//set extents
std::string minVal,maxVal;
convertExtents(this->getProperty("Extents"),minVal,maxVal);
std::vector<double> extents = this->getProperty("Extents");
std::vector<double> minVal,maxVal;
convertExtents(extents,minVal,maxVal);
Convert->setProperty("MinValues",minVal);
Convert->setProperty("MaxValues",maxVal);

Expand All @@ -281,15 +282,16 @@ namespace MDAlgorithms
Convert->setProperty("SplitInto",this->getPropertyValue("SplitInto"));
Convert->setProperty("SplitThreshold",this->getPropertyValue("SplitThreshold"));
Convert->setProperty("MaxRecursionDepth",this->getPropertyValue("MaxRecursionDepth"));
Convert->setProperty("MinRecursionDepth",this->getPropertyValue("MinRecursionDepth"));
std::string depth = this->getPropertyValue("MinRecursionDepth");
if(depth == "0") depth = "1"; // ConvertToMD does not understand 0 depth
Convert->setProperty("MinRecursionDepth",depth);

Convert->execute();
Convert->executeAsChildAlg();

IMDEventWorkspace_sptr iOut = Convert->getProperty("OutputWorkspace");
this->setProperty("OutputWorkspace",iOut);



}


Expand Down
9 changes: 5 additions & 4 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ void ConvertToMD::copyMetaData(API::IMDEventWorkspace_sptr mdEventWS, MDEvents::
expt->cacheDetectorGroupings(*mapping);
}

// and add it to the target workspace description for further usage as identifier for the workspaces, which come from this run.
// and add it to the target workspace description for further usage as the identifier for the workspaces, which come from this run.
targWSDescr.addProperty("RUN_INDEX",runIndex,true);

}
Expand Down Expand Up @@ -502,12 +502,13 @@ bool ConvertToMD::buildTargetWSDescription(API::IMDEventWorkspace_sptr spws,cons
// some conversion parameters can not be defined by the target workspace. They have to be retrieved from the input workspace
// and derived from input parameters.
oldWSDescr.setUpMissingParameters(targWSDescr);
// check inconsistencies
// set up target coordinate system and the dimension names/units
targWSDescr.m_RotMatrix = MsliceProj.getTransfMatrix(targWSDescr,QFrame,convertTo_);

// check inconsistencies, if the existing workspace can be used as target workspace.
oldWSDescr.checkWSCorresponsMDWorkspace(targWSDescr);
// reset new ws description name
targWSDescr =oldWSDescr;
// set up target coordinate system
targWSDescr.m_RotMatrix = MsliceProj.getTransfMatrix(targWSDescr,QFrame,convertTo_);
}
return createNewTargetWs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class ConvertToDiffractionMDWorkspace2Test : public CxxTest::TestSuite
"OutputDimensions", "Q (lab frame)");
TS_ASSERT( alg->isExecuted() );

MDEventWorkspace3Lean::sptr ws;
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3Lean>("testOutMD") );
MDEventWorkspace3::sptr ws;
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3>("testOutMD") );
TS_ASSERT(ws);
if (!ws) return;
TS_ASSERT_EQUALS( ws->getDimension(0)->getName(), "Q_lab_x");
Expand Down Expand Up @@ -79,10 +79,10 @@ class ConvertToDiffractionMDWorkspace2Test : public CxxTest::TestSuite
"OutputDimensions", "HKL");
TS_ASSERT( alg->isExecuted() );

TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3Lean>("testOutMD") );
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3>("testOutMD") );
TS_ASSERT(ws);
if (!ws) return;
TS_ASSERT_EQUALS( ws->getDimension(0)->getName(), "H");
TS_ASSERT_EQUALS( ws->getDimension(0)->getName(), "[H,0,0]");
TS_ASSERT_EQUALS( ws->getSpecialCoordinateSystem(), Mantid::API::HKL);

AnalysisDataService::Instance().remove("testOutMD");
Expand All @@ -93,7 +93,7 @@ class ConvertToDiffractionMDWorkspace2Test : public CxxTest::TestSuite
);
TS_ASSERT( alg->isExecuted() );

TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3Lean>("testOutMD") );
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3>("testOutMD") );
TS_ASSERT(ws);
if (!ws) return;
TS_ASSERT_EQUALS( ws->getDimension(0)->getName(), "Q_sample_x");
Expand Down Expand Up @@ -134,9 +134,9 @@ class ConvertToDiffractionMDWorkspace2Test : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING( alg.execute(); )
TS_ASSERT( alg.isExecuted() )

MDEventWorkspace3Lean::sptr ws;
MDEventWorkspace3::sptr ws;
TS_ASSERT_THROWS_NOTHING(
ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3Lean>("test_md3") );
ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3>("test_md3") );
TS_ASSERT(ws);
if (!ws) return;
size_t npoints = ws->getNPoints();
Expand All @@ -159,7 +159,7 @@ class ConvertToDiffractionMDWorkspace2Test : public CxxTest::TestSuite
TS_ASSERT( alg.isExecuted() )

TS_ASSERT_THROWS_NOTHING(
ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3Lean>("test_md3") );
ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3>("test_md3") );
TS_ASSERT(ws);
if (!ws) return;

Expand Down Expand Up @@ -188,10 +188,11 @@ class ConvertToDiffractionMDWorkspace2Test : public CxxTest::TestSuite
do_test_MINITOPAZ(TOF, 2);
}

void test_MINITOPAZ_OneEventPerBin_fromEventWorkspace()
/* void xest_MINITOPAZ_OneEventPerBin_fromEventWorkspace()
{
not yet implemented
do_test_MINITOPAZ(TOF, 1, true, false);
}
}*/

void test_MINITOPAZ_OneEventPerBin_fromWorkspace2D()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ class ConvertToDiffractionMDWorkspaceTest : public CxxTest::TestSuite
{
EventWorkspace_sptr in_ws = Mantid::MDEvents::MDEventsTestHelper::createDiffractionEventWorkspace(10);
AnalysisDataService::Instance().addOrReplace("testInEW", in_ws);
IAlgorithm_sptr alg;
IAlgorithm* alg;

alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", 6,
"InputWorkspace", "testInEW",
"OutputWorkspace", "testOutMD",
"OutputDimensions", "Q (lab frame)");
alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace",
"InputWorkspace=testInEW;OutputWorkspace=testOutMD;OutputDimensions=Q (lab frame)",1);
TS_ASSERT( alg->isExecuted() );

MDEventWorkspace3Lean::sptr ws;
Expand All @@ -55,28 +53,28 @@ class ConvertToDiffractionMDWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( ws->getSpecialCoordinateSystem(), Mantid::API::QLab);

// But you can't add to an existing one of the wrong dimensions type, if you choose Append
alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", 8,
"InputWorkspace", "testInEW",
"OutputWorkspace", "testOutMD",
"Append", "1",
"OutputDimensions", "HKL");
alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace",
"InputWorkspace=testInEW;"
"OutputWorkspace=testOutMD;"
"Append=1;"
"OutputDimensions=HKL",1);
TS_ASSERT( !alg->isExecuted() );

// If Append is False, then it does work. The workspace gets replaced
alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", 8,
"InputWorkspace", "testInEW",
"OutputWorkspace", "testOutMD",
"Append", "0",
"OutputDimensions", "HKL");
alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace",
"InputWorkspace=testInEW;"
"OutputWorkspace=testOutMD;"
"Append=0;"
"OutputDimensions=HKL",1);
TS_ASSERT( alg->isExecuted() );

// Let's remove the old workspace and try again - it will work.
AnalysisDataService::Instance().remove("testOutMD");
alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", 8,
"InputWorkspace", "testInEW",
"OutputWorkspace", "testOutMD",
"Append", "1",
"OutputDimensions", "HKL");
alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace",
"InputWorkspace=testInEW;"
"OutputWorkspace=testOutMD;"
"Append=1;"
"OutputDimensions=HKL",1);
TS_ASSERT( alg->isExecuted() );

TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3Lean>("testOutMD") );
Expand All @@ -86,10 +84,10 @@ class ConvertToDiffractionMDWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( ws->getSpecialCoordinateSystem(), Mantid::API::HKL);

AnalysisDataService::Instance().remove("testOutMD");
alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", 6,
"InputWorkspace", "testInEW",
"OutputWorkspace", "testOutMD",
"OutputDimensions", "Q (sample frame)"
alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace",
"InputWorkspace=testInEW;"
"OutputWorkspace=testOutMD;"
"OutputDimensions=Q (sample frame)",1
);
TS_ASSERT( alg->isExecuted() );

Expand Down
12 changes: 11 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/MDWSDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void MDWSDescription::setDimName(unsigned int nDim,const std::string &Name)
m_DimNames[nDim] = Name;
}
/** this is rather misleading function, as MD workspace does not currently have dimension units.
*It actually sets the units dimension names, which will be displayed along axis and have nothinbg in common with units, defined by unit factory */
*It actually sets the units for the dimension names, which will be displayed along axis and have nothinbg in common with units, defined by unit factory */
void MDWSDescription::setDimUnit(unsigned int nDim,const std::string &Unit)
{
if(nDim>=m_NDims)
Expand Down Expand Up @@ -143,6 +143,8 @@ void MDWSDescription::buildFromMDWS(const API::IMDEventWorkspace_const_sptr &pWS

}
m_Wtransf = Kernel::DblMatrix(pWS->getWTransf());
this->addProperty("W_MATRIX",pWS->getExperimentInfo(0)->run().getPropertyValueAsType<std::vector<double> >("W_MATRIX"),true);



}
Expand Down Expand Up @@ -190,6 +192,14 @@ void MDWSDescription::checkWSCorresponsMDWorkspace(MDEvents::MDWSDescription &N
if(m_Emode==Kernel::DeltaEMode::Undefined)
throw(std::invalid_argument("Workspace description has not been correctly defined, as emode has not been defined"));


for(size_t i=0;i<m_NDims;i++)
{
if(m_DimUnits[i] != NewMDWorkspaceD.m_DimUnits[i])
throw std::runtime_error("The existing MDEventWorkspace has different dimenson units than were requested! Either give a different worspace as the output, or change the OutputDimensions parameter.");
}


//TODO: More thorough checks may be nesessary to prevent adding different kind of workspaces e.g 4D |Q|-dE-T-P workspace to Q3d+dE ws
}

Expand Down
14 changes: 5 additions & 9 deletions Code/Mantid/Framework/MDEvents/src/MDWSTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,12 @@ Kernel::DblMatrix MDWSTransform::buildQTrahsf(MDEvents::MDWSDescription &TargWSD
return Transf*Scale*Wmat;
}

///** Build meaningful dimension names for different conversion modes
//*/
//void MDWSTransform::setQ3DDimensionsNames(MDEvents::MDWSDescription &TargWSDescription,const std::string &QScaleRequested)const
//{
// //axis units: convert string representation to any availible
// CoordScaling ScaleID = getQScaling(QScaleRequested);
// this->setQ3DDimensionsNames(TargWSDescription,ScaleID);
//
//}
/** Build meaningful dimension names for different conversion modes
* @param TargWSDescription the class-container to keep the dimension names and dimension unints
* @param FrameID -- the ID describing the target transformation frame (lab, sample, hkl)
* @param ScaleID -- the scale ID which define how the dimensions are scaled
*/
void MDWSTransform::setQ3DDimensionsNames(MDEvents::MDWSDescription &TargWSDescription,CnvrtToMD::TargetFrame FrameID,CnvrtToMD::CoordScaling ScaleID)const
{

Expand Down

0 comments on commit 6354c94

Please sign in to comment.