Skip to content

Commit

Permalink
Merge branch 'master' into feature/10330_threadpool_working_with_clang
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumsteve committed Oct 16, 2014
2 parents 0919e61 + 9895a3a commit c4408e0
Show file tree
Hide file tree
Showing 39 changed files with 4,260 additions and 290 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Expand Up @@ -588,6 +588,7 @@ set ( TEST_FILES
DiffractionFocussingTest.h
DivideTest.h
EditInstrumentGeometryTest.h
ElasticWindowTest.h
EstimatePDDetectorResolutionTest.h
ExponentialCorrectionTest.h
ExponentialTest.h
Expand Down
150 changes: 150 additions & 0 deletions Code/Mantid/Framework/Algorithms/test/ElasticWindowTest.h
@@ -0,0 +1,150 @@
#ifndef MANTID_ALGORITHMS_ELASTICWINDOWTEST_H_
#define MANTID_ALGORITHMS_ELASTICWINDOWTEST_H_

#include <cxxtest/TestSuite.h>

#include <iostream>
#include <iomanip>

#include "MantidKernel/System.h"

#include "MantidAlgorithms/ConvertUnits.h"
#include "MantidAlgorithms/CreateSampleWorkspace.h"
#include "MantidAlgorithms/ElasticWindow.h"
#include "MantidAlgorithms/Rebin.h"
#include "MantidAlgorithms/SetInstrumentParameter.h"

using namespace Mantid;
using namespace Mantid::Algorithms;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::Kernel::Units;

class ElasticWindowTest : public CxxTest::TestSuite
{
public:

void setUp()
{
// Create a workspace and format it for the ElasticWindow algorithm

CreateSampleWorkspace createAlg;
createAlg.initialize();
createAlg.setProperty("Function", "User Defined");
createAlg.setProperty("UserDefinedFunction", "name=Lorentzian,Amplitude=100,PeakCentre=12700,FWHM=20;name=LinearBackground,A0=0.01");
createAlg.setProperty("XMin", 27000.0);
createAlg.setProperty("XMax", 28000.0);
createAlg.setProperty("BinWidth", 10.0);
createAlg.setProperty("NumBanks", 1);
createAlg.setProperty("OutputWorkspace", "__ElasticWindowTest_sample");
createAlg.execute();

ConvertUnits convertUnitsAlg;
convertUnitsAlg.initialize();
convertUnitsAlg.setProperty("InputWorkspace", "__ElasticWindowTest_sample");
convertUnitsAlg.setProperty("Target", "DeltaE");
convertUnitsAlg.setProperty("EMode", "Indirect");
convertUnitsAlg.setProperty("Efixed", 1.555);
convertUnitsAlg.setProperty("OutputWorkspace", "__ElasticWindowTest_sample");
convertUnitsAlg.execute();

Rebin rebinAlg;
rebinAlg.initialize();
rebinAlg.setProperty("InputWorkspace", "__ElasticWindowTest_sample");
rebinAlg.setProperty("Params", "-0.2,0.004,0.2");
rebinAlg.setProperty("OutputWorkspace", "__ElasticWindowTest_sample");
rebinAlg.execute();

SetInstrumentParameter setParamAlg;
setParamAlg.initialize();
setParamAlg.setProperty("Workspace", "__ElasticWindowTest_sample");
setParamAlg.setProperty("ParameterName", "Efixed");
setParamAlg.setProperty("ParameterType", "Number");
setParamAlg.setProperty("Value", "1.555");
setParamAlg.execute();
}

/**
* Test initialization of the algorithm is successful.
*/
void test_init()
{
ElasticWindow alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT(alg.isInitialized());
}

/**
* Test running ElasticWindow with just the peak range defined.
*/
void test_peakOnly()
{
ElasticWindow elwinAlg;
elwinAlg.initialize();

TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("InputWorkspace", "__ElasticWindowTest_sample") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1Start", -0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1End", 0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQ", "__ElasticWindowTest_outputQ") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQSquared", "__ElasticWindowTest_outputQsq") );

TS_ASSERT_THROWS_NOTHING( elwinAlg.execute() );
TS_ASSERT( elwinAlg.isExecuted() );

MatrixWorkspace_sptr qWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("__ElasticWindowTest_outputQ");
verifyQworkspace(qWs);
}

/**
* Test running ElasticWindow with both the peak and background ranges defined.
*/
void test_peakAndBackground()
{
ElasticWindow elwinAlg;
elwinAlg.initialize();

TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("InputWorkspace", "__ElasticWindowTest_sample") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1Start", -0.04) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1End", 0.04) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range2Start", 0.05) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range2End", 0.06) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQ", "__ElasticWindowTest_outputQ") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQSquared", "__ElasticWindowTest_outputQsq") );

TS_ASSERT_THROWS_NOTHING( elwinAlg.execute() );
TS_ASSERT( elwinAlg.isExecuted() );

MatrixWorkspace_sptr qWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("__ElasticWindowTest_outputQ");
verifyQworkspace(qWs);

MatrixWorkspace_sptr q2Ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("__ElasticWindowTest_outputQsq");
verifyQ2workspace(q2Ws);
}

private:

/**
* Ensures that a workspace is valid output in Q.
*
* @param ws Workspace to test
*/
void verifyQworkspace(MatrixWorkspace_sptr ws)
{
std::string unitID = ws->getAxis(0)->unit()->unitID();
TS_ASSERT_EQUALS(unitID, "MomentumTransfer");
}

/**
* Ensures that a workspace is valid output in Q^2.
*
* @param ws Workspace to test
*/
void verifyQ2workspace(MatrixWorkspace_sptr ws)
{
std::string unitID = ws->getAxis(0)->unit()->unitID();
TS_ASSERT_EQUALS(unitID, "QSquared");
}

};

#endif /* MANTID_ALGORITHMS_ELASTICWINDOWTEST_H_ */
8 changes: 6 additions & 2 deletions Code/Mantid/Framework/DataHandling/src/LoadNXSPE.cpp
Expand Up @@ -2,11 +2,13 @@
#include "MantidKernel/UnitFactory.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidAPI/SpectraAxis.h"

#include <nexus/NeXusFile.hpp>
#include <nexus/NeXusException.hpp>
#include "MantidNexus/NexusClasses.h"


#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/Detector.h"
#include "MantidGeometry/Surfaces/Plane.h"
Expand Down Expand Up @@ -46,7 +48,7 @@ namespace DataHandling
//----------------------------------------------------------------------------------------------

/**
* Return the confidence with with this algorithm can load the file
* Return the confidence with this algorithm can load the file
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
Expand Down Expand Up @@ -94,7 +96,7 @@ namespace DataHandling
void LoadNXSPE::exec()
{
std::string filename = getProperty("Filename");
//quicly check if it's really nxspe
//quickly check if it's really nxspe
try
{
::NeXus::File file(filename);
Expand Down Expand Up @@ -244,6 +246,8 @@ namespace DataHandling
// Need to get hold of the parameter map
Geometry::ParameterMap& pmap = outputWS->instrumentParameters();
outputWS->getAxis(0)->unit() = UnitFactory::Instance().create("DeltaE");
outputWS->setYUnit("SpectraNumber");

std::vector<double>::iterator itdata=data.begin(),iterror=error.begin(),itdataend,iterrorend;
API::Progress prog = API::Progress(this, 0.0, 0.9, numSpectra);
for (std::size_t i=0; i<numSpectra; ++i)
Expand Down
68 changes: 26 additions & 42 deletions Code/Mantid/Framework/DataObjects/src/Peak.cpp
Expand Up @@ -528,6 +528,7 @@ namespace DataObjects
*/
bool Peak::findDetector()
{
bool found = false;
// Scattered beam direction
V3D oldDetPos = detPos;
V3D beam = detPos - samplePos;
Expand All @@ -543,55 +544,38 @@ namespace DataObjects
this->setDetectorID(det->getID());
// The old detector position is not more precise if it comes from FindPeaksMD
detPos = det->getPos();
return true;
found = true;
}
//fix for gaps between tubes
//Use tube-gap parameter in instrument parameter file to find peaks with center in gaps between tubes
else if (m_inst->hasParameter("tube-gap"))
{
std::vector<double> gaps = m_inst->getNumberParameter("tube-gap", true);
if (gaps.empty()) return false;
const double gap = static_cast<double>(gaps.front());
V3D beam1 = beam + V3D(0.,0.,gap);
tracker.traceFromSample(beam1);
IDetector_const_sptr det1 = tracker.getDetectorResult();
V3D beam2 = beam + V3D(0.,0.,-gap);
tracker.traceFromSample(beam2);
IDetector_const_sptr det2 = tracker.getDetectorResult();
if (det1 && det2)
if (!gaps.empty())
{
// Set the detector ID to one of the neighboring pixels
this->setDetectorID(static_cast<int>(det1->getID()));;
detPos = det1->getPos() ;
return true;
}
beam1 = beam + V3D(gap,0.,0.);
tracker.traceFromSample(beam1);
det1 = tracker.getDetectorResult();
beam2 = beam + V3D(-gap,0.,0.);
tracker.traceFromSample(beam2);
det2 = tracker.getDetectorResult();
if (det1 && det2)
{
// Set the detector ID to one of the neighboring pixels
this->setDetectorID(static_cast<int>(det1->getID()));;
detPos = det1->getPos() ;
return true;
}
beam1 = beam + V3D(0.,gap,0.);
tracker.traceFromSample(beam1);
det1 = tracker.getDetectorResult();
beam2 = beam + V3D(0.,-gap,0.);
tracker.traceFromSample(beam2);
det2 = tracker.getDetectorResult();
if (det1 && det2)
{
// Set the detector ID to one of the neighboring pixels
this->setDetectorID(static_cast<int>(det1->getID()));;
detPos = det1->getPos() ;
return true;
const double gap = static_cast<double>(gaps.front());
// try adding and subtracting tube-gap in 3 q dimensions to see if you can find detectors on each side of tube gap
for(int i=0;i<3;i++)
{
V3D gapDir = V3D(0.,0.,0.);
gapDir[i] = gap;
V3D beam1 = beam + gapDir;
tracker.traceFromSample(beam1);
IDetector_const_sptr det1 = tracker.getDetectorResult();
V3D beam2 = beam - gapDir;
tracker.traceFromSample(beam2);
IDetector_const_sptr det2 = tracker.getDetectorResult();
if (det1 && det2)
{
// Set the detector ID to one of the neighboring pixels
this->setDetectorID(static_cast<int>(det1->getID()));;
detPos = det1->getPos() ;
found = true;
break;
}
}
}
}
return false;
return found;
}

//----------------------------------------------------------------------------------------------
Expand Down

0 comments on commit c4408e0

Please sign in to comment.