Skip to content

Commit

Permalink
refs #5537 This mainly fixes it. Only the doc remains.
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Jul 3, 2012
1 parent 7ec433e commit 8bb954a
Show file tree
Hide file tree
Showing 6 changed files with 636 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidKernel/System.h"
#include "MantidKernel/Timer.h"
#include "MantidMDAlgorithms/ConvertToMDEvents.h"
#include "MantidMDAlgorithms/ConvertToMD.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include "MantidTestHelpers/MDEventsTestHelper.h"
Expand All @@ -22,13 +22,13 @@ using namespace Mantid::DataObjects;
using namespace Mantid::MDAlgorithms;
using namespace Mantid::MDEvents;

class ConvertTo3DdETestHelper: public ConvertToMDEvents
class ConvertTo3DdETestHelper: public ConvertToMD
{
public:
ConvertTo3DdETestHelper(){};
};

// Test is transformed from ConvetToQ3DdE but actually tests some aspects of ConvertToMDEvents algorithm.
// Test is transformed from ConvetToQ3DdE but actually tests some aspects of ConvertToMD algorithm.
class ConvertToQ3DdETest : public CxxTest::TestSuite
{
std::auto_ptr<ConvertTo3DdETestHelper> pAlg;
Expand Down
67 changes: 67 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/ConvertToMDFactoryTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef MANTID_MD_CONVERT2_MDEV_FACTORY_TEST_H_
#define MANTID_MD_CONVERT2_MDEV_FACTORY_TEST_H_

#include "MantidDataObjects/EventWorkspace.h"
#include "MantidKernel/System.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidMDEvents/MDTransfFactory.h"
#include <cxxtest/TestSuite.h>
#include <iomanip>
#include <iostream>

#include "MantidMDEvents/MDTransfNoQ.h"
#include "MantidMDEvents/MDTransfModQ.h"
#include "MantidMDEvents/MDTransfQ3D.h"


using namespace Mantid;
using namespace Mantid::MDEvents;


//
class ConvertToMDEventsFactoryTest : public CxxTest::TestSuite
{
public:
static ConvertToMDEventsFactoryTest *createSuite() { return new ConvertToMDEventsFactoryTest(); }
static void destroySuite(ConvertToMDEventsFactoryTest * suite) { delete suite; }

void testInit()
{
std::vector<std::string> keys;

TS_ASSERT_THROWS_NOTHING(keys = MDTransfFactory::Instance().getKeys());
// we already have three transformation defined. It can be only more in a future;
TS_ASSERT(keys.size()>2);
}

void testWrongAlgThrows()
{
TS_ASSERT_THROWS(MDTransfFactory::Instance().create("Non_existing_subalgorithm"),Kernel::Exception::NotFoundError);
}

void testGetAlg()
{
MDTransf_sptr transf;

TS_ASSERT_THROWS_NOTHING(transf=MDTransfFactory::Instance().create("CopyToMD"));
TS_ASSERT(dynamic_cast<MDTransfNoQ *>(transf.get()));

TS_ASSERT_THROWS_NOTHING(transf=MDTransfFactory::Instance().create("|Q|"));
TS_ASSERT(dynamic_cast<MDTransfModQ *>(transf.get()));

TS_ASSERT_THROWS_NOTHING(transf=MDTransfFactory::Instance().create("Q3D"));
TS_ASSERT(dynamic_cast<MDTransfQ3D *>(transf.get()));

}

//
ConvertToMDEventsFactoryTest()
{
API::FrameworkManager::Instance();
}

};


#endif /* MANTID_MD_CONVERT2_MDEV_SUBALGFACTORY_TEST_H_ */

78 changes: 78 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/ConvertToMDParamsTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#ifndef MANTID_CONV2MD_PARAMS_TEST_H_
#define MANTID_CONV2MD_PARAMS_TEST_H_


#include "MantidAPI/TextAxis.h"
#include "MantidAPI/NumericAxis.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidMDEvents/MDWSDescription.h"

#include <cxxtest/TestSuite.h>
#include <iomanip>
#include <iostream>

using namespace Mantid;
using namespace Mantid::Kernel;
using namespace Mantid::API;

using namespace Mantid::MDEvents;

class ConvertToMDParamsTest : public CxxTest::TestSuite
{
public:
static ConvertToMDParamsTest *createSuite() { return new ConvertToMDParamsTest(); }
static void destroySuite(ConvertToMDParamsTest * suite) { delete suite; }

// --> GET DIMENSIONS FROM WS MATRIX:
//--> this test should go on unit conversion
//void testNeedsNumericAxis()
//{
// MDEvents::MDWSDescription TWS;
// Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::Create2DWorkspace(4,10);
// ws2D->replaceAxis(0,new API::TextAxis(3));
// std::vector<std::string> add_dim_names;
// std::vector<double> min(3,-10),max(3,10);
// TWS.setMinMax(min,max);
//
// TS_ASSERT_THROWS(TWS.buildFromMatrixWS(ws2D,"Q3D","Elastic",add_dim_names),std::invalid_argument);
//}
void testGetWS4DimIDFine()
{
Mantid::API::MatrixWorkspace_sptr ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(4,10,true);
ws2D->mutableRun().addProperty("Ei",12.,"meV",true);

MDEvents::MDWSDescription TWS;
std::vector<double> min(4,-10),max(4,10);
TWS.setMinMax(min,max);

std::vector<std::string> other_dim_names;


TS_ASSERT_THROWS_NOTHING(TWS.buildFromMatrixWS(ws2D,"Q3D","Direct",other_dim_names));

TSM_ASSERT_EQUALS("Inelastic workspace will produce 4 dimensions",4,TWS.nDimensions());
std::vector<std::string> dim_units = TWS.getDimUnits();
TSM_ASSERT_EQUALS("Last dimension of Inelastic transformation should be DeltaE","DeltaE",dim_units[3]);
TSM_ASSERT_EQUALS("Alg ID would be: ","Q3D",TWS.AlgID);
TSM_ASSERT("detector infromation should be present in the workspace ",!TWS.isDetInfoLost());

TS_ASSERT_THROWS_NOTHING(TWS.buildFromMatrixWS(ws2D,TWS.AlgID,"Indirect",other_dim_names));



//std::vector<std::string> dimID= TWS.getDefaultDimIDQ3D(1);
//for(size_t i=0;i<4;i++)
//{
// TS_ASSERT_EQUALS(dimID[i],TWS.dimIDs[i]);
// TS_ASSERT_EQUALS(dimID[i],TWS.dimNames[i]);
//}


}



};

//
#endif
160 changes: 160 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/ConvertToMDUnitsConvTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#ifndef CONVERT2_MDEVENTS_UNITS_CONVERSION_TEST_H_
#define CONVERT2_MDEVENTS_UNITS_CONVERSION_TEST_H_

#include <cxxtest/TestSuite.h>
#include "MantidAPI/FrameworkManager.h"
#include "MantidKernel/UnitFactory.h"

#include "MantidAPI/NumericAxis.h"
#include "MantidMDEvents/ConvToMDPreprocDet.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidAPI/Progress.h"

#include "MantidMDEvents/UnitsConversionHelper.h"
#include "MantidMDEvents/MDWSDescription.h"

using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace Mantid::MDEvents;



class ConvertToMDUnitsConvTest : public CxxTest::TestSuite
{
Mantid::API::MatrixWorkspace_sptr ws2D;
ConvToMDPreprocDet det_loc;

public:
static ConvertToMDUnitsConvTest *createSuite() {
return new ConvertToMDUnitsConvTest();
}
static void destroySuite(ConvertToMDUnitsConvTest * suite) { delete suite; }

void testSpecialConversionTOF()
{
double factor,power;

const Kernel::Unit_sptr pThisUnit=Kernel::UnitFactory::Instance().create("Wavelength");
TS_ASSERT(!pThisUnit->quickConversion("MomentumTransfer",factor,power));
}

void testTOFConversionRuns()
{

Kernel::Unit_sptr pSourceWSUnit = Kernel::UnitFactory::Instance().create("Wavelength");
Kernel::Unit_sptr pWSUnit = Kernel::UnitFactory::Instance().create("MomentumTransfer");
double delta;
double L1(10),L2(10),TwoTheta(0.1),efix(10);
int emode(0);
TS_ASSERT_THROWS_NOTHING(pWSUnit->initialize(L1,L2,TwoTheta,emode,efix,delta));
TS_ASSERT_THROWS_NOTHING(pSourceWSUnit->initialize(L1,L2,TwoTheta,emode,efix,delta));

double X0(5);
double tof(0) ,k_tr(0);
TS_ASSERT_THROWS_NOTHING(tof = pSourceWSUnit->singleToTOF(X0));
TS_ASSERT_THROWS_NOTHING(k_tr = pWSUnit->singleFromTOF(tof));
}



void testConvertFastFromInelasticWS()
{
UnitsConversionHelper Conv;
MDWSDescription WSD;

// ws description currently needs min/max to be set properly
std::vector<double> min(2,-10),max(2,10);
WSD.setMinMax(min,max);

WSD.buildFromMatrixWS(ws2D,"|Q|","Direct");
WSD.setDetectors(det_loc);


// initialize peculiar conversion from ws units to DeltaE_inWavenumber
TS_ASSERT_THROWS_NOTHING(Conv.initialize(WSD,"DeltaE_inWavenumber"));

const MantidVec& X = ws2D->readX(0);
size_t n_bins = X.size()-1;
for(size_t i=0;i<n_bins;i++){
TS_ASSERT_DELTA(X[i]*8.06554465,Conv.convertUnits(X[i]),1.e-4);
}

}
void testConvertToTofInelasticWS()
{
UnitsConversionHelper Conv;
MDWSDescription WSD;

// ws description currently needs min/max to be set properly
std::vector<double> min(2,-10),max(2,10);
WSD.setMinMax(min,max);

WSD.buildFromMatrixWS(ws2D,"|Q|","Direct");
WSD.setDetectors(det_loc);

// initalize Convert to TOF
TS_ASSERT_THROWS_NOTHING(Conv.initialize(WSD,"TOF"));


const MantidVec& X = ws2D->readX(0);
MantidVec E_storage(X.size());
TS_ASSERT_THROWS_NOTHING(Conv.updateConversion(0));

size_t n_bins = X.size();
std::vector<double> TOFS(n_bins);
for(size_t i=0;i<n_bins;i++){
E_storage[i]=X[i];
TOFS[i] =Conv.convertUnits(X[i]);
}

// Let WS know that it is in TOF now (one column)
MantidVec& T = ws2D->dataX(0);

NumericAxis *pAxis0 = new NumericAxis(n_bins-1);
for(size_t i=0; i < n_bins-1; i++){
double Tm =0.5*(TOFS[i]+TOFS[i+1]);
pAxis0->setValue(i,Tm);
T[i]=TOFS[i];
}
T[n_bins-1]=TOFS[n_bins-1];

pAxis0->setUnit("TOF");
ws2D->replaceAxis(0,pAxis0);

// initialize matrix ws description, to the same number of dimensions as before
WSD.buildFromMatrixWS(ws2D,"|Q|","Direct");

//initialize Convert back;
TS_ASSERT_THROWS_NOTHING(Conv.initialize(WSD,"DeltaE"));
TS_ASSERT_THROWS_NOTHING(Conv.updateConversion(0));

for(size_t i=0;i<n_bins;i++){
TS_ASSERT_DELTA(E_storage[i],Conv.convertUnits(TOFS[i]),1.e-5);
}
}


ConvertToMDUnitsConvTest()
{

API::FrameworkManager::Instance();

std::vector<double> L2(5,5);
std::vector<double> polar(5,(30./180.)*3.1415926);
polar[0]=0;
std::vector<double> azimutal(5,0);
azimutal[1]=(45./180.)*3.1415936;
azimutal[2]=(90./180.)*3.1415936;
azimutal[3]=(135./180.)*3.1415936;
azimutal[4]=(180./180.)*3.1415936;

int numBins=10;
ws2D =WorkspaceCreationHelper::createProcessedInelasticWS(L2, polar, azimutal,numBins,-1,3,3);

det_loc.buildFakeDetectorsPositions(ws2D);


}
};
#endif

0 comments on commit 8bb954a

Please sign in to comment.