Skip to content

Commit

Permalink
refs #7144 More refactoring
Browse files Browse the repository at this point in the history
Work in progress still
  • Loading branch information
DereckKachere committed Jun 14, 2013
1 parent 3e823dc commit ba26da9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
23 changes: 9 additions & 14 deletions Code/Mantid/Framework/Algorithms/src/ConvertSpectrumAxis2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,11 @@ namespace Algorithms
if (emodeStr == "Direct") emode=1;
else if (emodeStr == "Indirect") emode=2;
const double delta = 0.0;
double efixed, sineTheta, wavelength, k, elasticQ, elasticQSquared;

for ( size_t i = 0; i < m_nHist; i++ )
{
std::vector<double> xval;
xval.push_back(m_inputWS->readX(i).front());
xval.push_back(m_inputWS->readX(i).back());
IDetector_const_sptr detector = m_inputWS->getDetector(i);
double twoTheta, l1val, l2;
double twoTheta, l1val, l2, efixed;
if ( ! detector->isMonitor() )
{
twoTheta = m_inputWS->detectorTwoTheta(detector);
Expand All @@ -172,26 +168,25 @@ namespace Algorithms
efixed = DBL_MIN;
}

sineTheta = sin(twoTheta/2);
const double sineTheta = sin(twoTheta/2);

//Calculate the wavelength to allow it to be used to convert to elasticQ.
wavelength = Mantid::PhysicalConstants::h/(sqrt(2*efixed*Mantid::PhysicalConstants::NeutronMass));
double wavelength = Mantid::PhysicalConstants::h/(sqrt(2*efixed*Mantid::PhysicalConstants::NeutronMass));
//The constant k.
k = (2*M_PI)/wavelength;


const double k = (2*M_PI)/wavelength;

// MomentumTransfer
double elasticQ = k*2*sineTheta;

if(targetUnit == "ElasticQ")
{
// MomentumTransfer
elasticQ = k*2*sineTheta;

m_indexMap.insert(std::make_pair(elasticQ, i));
}

else if(targetUnit == "ElasticQSquared")
{
// QSquared
elasticQSquared = (k*2*sineTheta)*(k*2*sineTheta);
double elasticQSquared = elasticQ*elasticQ;

m_indexMap.insert(std::make_pair(elasticQSquared, i));
}
Expand Down
26 changes: 17 additions & 9 deletions Code/Mantid/Framework/Algorithms/test/ConvertSpectrumAxis2Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class ConvertSpectrumAxis2Test : public CxxTest::TestSuite
AnalysisDataService::Instance().remove(outputWS);
}

void estTargetElasticQ() // The new version of this alg follows the standard for the naming of units.
void testTargetElasticQ() // The new version of this alg follows the standard for the naming of units.
{
std::string inputWS("inWS");
const std::string outputWS("outWS");
Expand All @@ -185,6 +185,9 @@ class ConvertSpectrumAxis2Test : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING( qAxis = output->getAxis(1) );
TS_ASSERT( qAxis->isNumeric() );
TS_ASSERT_EQUALS( qAxis->unit()->unitID(), "MomentumTransfer");

TS_ASSERT_DELTA( (*qAxis)(0), 0.0000, 0.0001 );

//TS_ASSERT_EQUALS( qAxis->unit()->label(), Mantid::Kernel::UnitFactory::Instance().create("MomentumTransfer")->label() )
// Check axis is correct length
TS_ASSERT_THROWS( (*qAxis)(2), Mantid::Kernel::Exception::IndexError );
Expand All @@ -201,7 +204,7 @@ class ConvertSpectrumAxis2Test : public CxxTest::TestSuite
AnalysisDataService::Instance().remove(outputWS);
}

void testTargetElasticQSquared() // The new version of this alg follows the standard for the naming of units.
void estTargetElasticQSquared() // The new version of this alg follows the standard for the naming of units.
{
std::string inputWS("inWS");
const std::string outputWS("outWS");
Expand All @@ -212,14 +215,19 @@ class ConvertSpectrumAxis2Test : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING( input = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(inputWS) );
TS_ASSERT_THROWS_NOTHING( output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outputWS) );

// Should now have a numeric axis up the side, with units of Q
const Axis* qAxis = 0;
TS_ASSERT_THROWS_NOTHING( qAxis = output->getAxis(1) );
TS_ASSERT( qAxis->isNumeric() );
TS_ASSERT_EQUALS( qAxis->unit()->unitID(), "QSquared");
//TS_ASSERT_EQUALS( qAxis->unit()->label(), Mantid::Kernel::UnitFactory::Instance().create("MomentumTransfer")->label() )
// Should now have a numeric axis up the side, with units of Q^2
const Axis* q2Axis = 0;
TS_ASSERT_THROWS_NOTHING( q2Axis = output->getAxis(1) );
TS_ASSERT( q2Axis->isNumeric() );
TS_ASSERT_EQUALS( q2Axis->unit()->unitID(), "QSquared");

TS_ASSERT_DELTA( (*q2Axis)(0), 0.0000, 0.0001 );

//double efixed = Mantid::Algorithms::ConvertSpectrumAxis2::getEfixed(;
//TS_ASSERT_DELTA( (*q2Axis)(1), ((sqrt(2 * Mantid::Algorithms::ConvertSpectrumAxis2::getEfixed * Mantid::PhysicalConstants::NeutronMass)) * 4 * M_PI/(Mantid::PhysicalConstants::h)), 0.0001 );

// Check axis is correct length
TS_ASSERT_THROWS( (*qAxis)(2), Mantid::Kernel::Exception::IndexError );
TS_ASSERT_THROWS( (*q2Axis)(2), Mantid::Kernel::Exception::IndexError );

TS_ASSERT_EQUALS( input->readX(0), output->readX(0) );
TS_ASSERT_EQUALS( input->readY(0), output->readY(0) );
Expand Down

0 comments on commit ba26da9

Please sign in to comment.