Skip to content

Commit

Permalink
refs #4572 Some unit tests for new behavior.
Browse files Browse the repository at this point in the history
checks if the detector lost info propagates properly.
  • Loading branch information
abuts committed Jan 22, 2012
1 parent 1af04d8 commit 0e8f47f
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDEventsTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class Convert2AnyTestHelper: public ConvertToMDEvents
return ConvertToMDEvents::identifyTheAlg(inMatrixWS,Q_mode_req, dE_mode_req,other_dim_names,false,TWSD);
}
std::string identifyMatrixAlg(API::MatrixWorkspace_const_sptr inMatrixWS,const std::string &Q_mode_req, const std::string &dE_mode_req,
std::vector<std::string> &outws_dim_names,std::vector<std::string> &outws_dim_units){
bool is_detInfoDefined;
return ConvertToMDEvents::identifyMatrixAlg(inMatrixWS,Q_mode_req, dE_mode_req,outws_dim_names,outws_dim_units,is_detInfoDefined);
std::vector<std::string> &outws_dim_names,std::vector<std::string> &outws_dim_units,bool &is_detInfoLost){

return ConvertToMDEvents::identifyMatrixAlg(inMatrixWS,Q_mode_req, dE_mode_req,outws_dim_names,outws_dim_units,is_detInfoLost);
}
//
std::string parseQMode(const std::string &Q_mode_req,const std::vector<std::string> &ws_dim_names,const std::vector<std::string> &ws_dim_units,
Expand Down Expand Up @@ -349,19 +349,22 @@ void testNeedsNumericAxis(){
ws2D->replaceAxis(0,new API::TextAxis(3));
std::vector<std::string> dim_ID;
std::vector<std::string> dim_units;
TS_ASSERT_THROWS(pAlg->identifyMatrixAlg(ws2D,"QhQkQl","",dim_ID,dim_units),std::invalid_argument);
bool is_detInfoLost;
TS_ASSERT_THROWS(pAlg->identifyMatrixAlg(ws2D,"QhQkQl","",dim_ID,dim_units,is_detInfoLost),std::invalid_argument);
}
void testGetWS4DimIDFine(){
Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(4,10,true);

std::vector<std::string> dim_ID;
std::vector<std::string> dim_units;
std::string Alg_ID;
TS_ASSERT_THROWS_NOTHING(Alg_ID=pAlg->identifyMatrixAlg(ws2D,"QhQkQl","Direct",dim_ID,dim_units));
bool is_detInfoLost;
TS_ASSERT_THROWS_NOTHING(Alg_ID=pAlg->identifyMatrixAlg(ws2D,"QhQkQl","Direct",dim_ID,dim_units,is_detInfoLost));

TSM_ASSERT_EQUALS("Inelastic workspace will produce 4 dimensions",4,dim_ID.size());
TSM_ASSERT_EQUALS("Last dimension of Inelastic transformation should be DeltaE","DeltaE",dim_units[3]);
TSM_ASSERT_EQUALS("Alg ID would be: ","WS2DQhQkQlDirectCnvNo",Alg_ID);
TS_ASSERT(!is_detInfoLost);
}
void testGetWS3DimIDFine(){
Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(4,10,true);
Expand All @@ -374,12 +377,13 @@ void testGetWS3DimIDFine(){
std::vector<std::string> dim_ID;
std::vector<std::string> dim_units;
std::string Alg_ID;
TS_ASSERT_THROWS_NOTHING(Alg_ID=pAlg->identifyMatrixAlg(ws2D,"QhQkQl","Elastic",dim_ID,dim_units));
bool is_detInfoLost;
TS_ASSERT_THROWS_NOTHING(Alg_ID=pAlg->identifyMatrixAlg(ws2D,"QhQkQl","Elastic",dim_ID,dim_units, is_detInfoLost));

TSM_ASSERT_EQUALS("Inelastic workspace will produce 3 dimensions",3,dim_ID.size());
TSM_ASSERT_EQUALS("Last dimension of Elastic transformation should be ","Momentum",dim_units[2]);
TSM_ASSERT_EQUALS("Alg ID would be: ","WS2DQhQkQlElasticCnvByTOF",Alg_ID);

TS_ASSERT(!is_detInfoLost);
}
void testGetWSDimNames2AxisNoQ(){
Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::Create2DWorkspace(4,10);
Expand All @@ -397,7 +401,10 @@ void testGetWSDimNames2AxisNoQ(){
std::vector<std::string> dim_ID;
std::vector<std::string> dim_units;
std::string AlgID;
TS_ASSERT_THROWS_NOTHING(AlgID=pAlg->identifyMatrixAlg(ws2D,"","",dim_ID,dim_units));
bool is_detInfoLost;
TS_ASSERT_THROWS_NOTHING(AlgID=pAlg->identifyMatrixAlg(ws2D,"","",dim_ID,dim_units, is_detInfoLost));

TSM_ASSERT("Det info should be undefined an an numeric axis is along axis 2",is_detInfoLost);

TS_ASSERT_EQUALS(2,dim_ID.size());
TS_ASSERT_EQUALS("Dim1",dim_ID[0]);
Expand Down Expand Up @@ -446,11 +453,12 @@ void testIdentifyMatrixAlg_1()
pAx->title() = ws_dim_names[1];
pAx->setUnit("QSquared");
ws2D->replaceAxis(1,pAx);
bool is_detInfoLost;


TS_ASSERT_EQUALS("WS2DCnvNo",pAlg->identifyMatrixAlg(ws2D,"","",dim_names,dim_units));
TS_ASSERT_EQUALS("WS2DCnvNo",pAlg->identifyMatrixAlg(ws2D,"","",dim_names,dim_units,is_detInfoLost));
TS_ASSERT_EQUALS(ws_dim_names[0],dim_names[0]);
TS_ASSERT_EQUALS(ws_dim_names[1],dim_names[1]);
TSM_ASSERT("Det info should be undefined an an numeric axis is along axis 2",is_detInfoLost);

}

Expand All @@ -459,39 +467,43 @@ void testIdentifyMatrixAlg_2()
{
Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::Create2DWorkspace(4,10);
std::vector<std::string> dim_names,dim_units;
bool is_detInfoLost;

API::NumericAxis *
pAx = new API::NumericAxis(3);
pAx->setUnit("TOF");
ws2D->replaceAxis(0,pAx);
TSM_ASSERT_THROWS_NOTHING("Elastic conversion needs X-axis to be in an Energy-related units",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units));
TSM_ASSERT_THROWS_NOTHING("Elastic conversion needs X-axis to be in an Energy-related units",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units,is_detInfoLost));
TSM_ASSERT("Det info should be defined for conversion",!is_detInfoLost);

pAx = new API::NumericAxis(3);
pAx->setUnit("Wavelength");
ws2D->replaceAxis(0,pAx);
// This is probably bug in conversion --> does not work in elastic mode
TSM_ASSERT_THROWS_NOTHING("Elastic conversion needs X-axis to be in an Energy-related units",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units));
TSM_ASSERT_THROWS_NOTHING("Elastic conversion needs X-axis to be in an Energy-related units",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units,is_detInfoLost));
//TSM_ASSERT_THROWS("Can not convert wavelength to momentum transfer in elastic mode ",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units),std::invalid_argument);
TSM_ASSERT("Det info should be defined for conversion",!is_detInfoLost);

pAx = new API::NumericAxis(3);
pAx->setUnit("Energy");
ws2D->replaceAxis(0,pAx);
// This is probably bug in conversion --> does not work in elastic mode
TSM_ASSERT_THROWS_NOTHING("Elastic conversion needs X-axis to be in an Energy-related units",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units));
TSM_ASSERT_THROWS_NOTHING("Elastic conversion needs X-axis to be in an Energy-related units",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units,is_detInfoLost));
// TSM_ASSERT_THROWS("Can not convert Energy to momentum transfer in elastic mode ",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units),std::invalid_argument);

TSM_ASSERT("Det info should be defined for conversion",!is_detInfoLost);

pAx = new API::NumericAxis(3);
pAx->setUnit("dSpacing");
ws2D->replaceAxis(0,pAx);
TSM_ASSERT_THROWS_NOTHING("Elastic conversion needs X-axis to be in an Energy-related units",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units));

TSM_ASSERT_THROWS_NOTHING("Elastic conversion needs X-axis to be in an Energy-related units",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units,is_detInfoLost));
TSM_ASSERT("Det info should be defined for conversion",!is_detInfoLost);

pAx = new API::NumericAxis(3);
pAx->setUnit("TOF");
ws2D->replaceAxis(0,pAx);
TS_ASSERT_EQUALS("WS2D|Q|ElasticCnvFromTOF",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units));
TS_ASSERT_EQUALS("WS2D|Q|ElasticCnvFromTOF",pAlg->identifyMatrixAlg(ws2D,"|Q|","Elastic",dim_names,dim_units,is_detInfoLost));

TSM_ASSERT("Det info should be defined for conversion",!is_detInfoLost);
TSM_ASSERT_EQUALS("One dim name came from Q (this can be logically wrong)",1,dim_names.size());
TS_ASSERT_EQUALS(dim_names[0],"|Q|");

Expand All @@ -501,49 +513,55 @@ void testIdentifyMatrixAlg_3()
{
Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::Create2DWorkspace(4,10);
std::vector<std::string> dim_names,dim_units;
bool is_detInfoLost;

API::NumericAxis *pAx = new API::NumericAxis(3);
pAx->title()="A";
pAx->setUnit("DeltaE");
ws2D->replaceAxis(0,pAx);

TS_ASSERT_EQUALS("WS2D|Q|DirectCnvNo",pAlg->identifyMatrixAlg(ws2D,"|Q|","Direct",dim_names,dim_units));
TS_ASSERT_EQUALS("WS2D|Q|DirectCnvNo",pAlg->identifyMatrixAlg(ws2D,"|Q|","Direct",dim_names,dim_units,is_detInfoLost));
TSM_ASSERT_EQUALS("One dimension comes from Q",2,dim_names.size());
TS_ASSERT_EQUALS(dim_names[0],"|Q|");
TS_ASSERT_EQUALS(dim_names[1],"DeltaE");
TSM_ASSERT("Det info should be defined for conversion",!is_detInfoLost);
}

void testIdentifyMatrixAlg_4()
{
std::vector<std::string> dim_names,dim_units;
Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::Create2DWorkspace(4,10);
bool is_detInfoLost;

API::NumericAxis *pAx = new API::NumericAxis(3);
pAx->title()="A";
pAx->setUnit("DeltaE");
ws2D->replaceAxis(0,pAx);

TS_ASSERT_EQUALS("WS2D|Q|IndirectCnvNo",pAlg->identifyMatrixAlg(ws2D,"|Q|","Indirect",dim_names,dim_units));
TS_ASSERT_EQUALS("WS2D|Q|IndirectCnvNo",pAlg->identifyMatrixAlg(ws2D,"|Q|","Indirect",dim_names,dim_units,is_detInfoLost));
TSM_ASSERT_EQUALS("One dim name came from Q (this can be wrong)",2,dim_names.size());
TS_ASSERT_EQUALS(dim_names[0],"|Q|");
TS_ASSERT_EQUALS(dim_names[1],"DeltaE");
TSM_ASSERT("Det info should be defined for conversion",!is_detInfoLost);
}
void testIdentifyMatrixAlg_5()
{
std::vector<std::string> dim_names,dim_units;
Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::Create2DWorkspace(4,10);
bool is_detInfoLost;

API::NumericAxis *pAx = new API::NumericAxis(3);
pAx->title()="A";
pAx->setUnit("DeltaE");
ws2D->replaceAxis(0,pAx);

TS_ASSERT_EQUALS("WS2DQhQkQlIndirectCnvNo",pAlg->identifyMatrixAlg(ws2D,"QhQkQl","Indirect",dim_names,dim_units));
TS_ASSERT_EQUALS("WS2DQhQkQlIndirectCnvNo",pAlg->identifyMatrixAlg(ws2D,"QhQkQl","Indirect",dim_names,dim_units,is_detInfoLost));
TSM_ASSERT_EQUALS("One dim name came from Q (this can be wrong)",4,dim_names.size());
TS_ASSERT_EQUALS(dim_names[0],"Q1");
TS_ASSERT_EQUALS(dim_names[1],"Q2");
TS_ASSERT_EQUALS(dim_names[2],"Q3");
TS_ASSERT_EQUALS(dim_names[3],"DeltaE");
TSM_ASSERT("Det info should be defined for conversion",!is_detInfoLost);
}

void testSetUpThrow()
Expand Down

0 comments on commit 0e8f47f

Please sign in to comment.