Skip to content

Commit

Permalink
refs #4013 Can set number of nearest neighbours to use via algorithm …
Browse files Browse the repository at this point in the history
…interface
  • Loading branch information
OwenArnold committed Nov 3, 2011
1 parent 483f40c commit 3385ec4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
19 changes: 11 additions & 8 deletions Code/Mantid/Framework/Algorithms/src/NormaliseByVanadium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include "MantidAPI/WorkspaceOpOverloads.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/CPUTimer.h"

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

namespace Mantid
{
Expand Down Expand Up @@ -45,21 +47,20 @@ namespace Algorithms
"The name of the vanadium Workspace2D to take as input");
declareProperty(new WorkspaceProperty<>("OutputWorkspace","",Direction::Output),
"The name of the workspace in which to store the result");
declareProperty(new PropertyWithValue<int>("NumberOfNeighbours", 8, new BoundedValidator<int>(), Direction::Input), "The number of neighbours to utilise. Defaults to 8.");
}

/// Run the algorithm
void NormaliseByVanadium::exec()
{
MatrixWorkspace_sptr sampleWS = getProperty("SampleInputWorkspace");
MatrixWorkspace_sptr vanadiumWS = getProperty("VanadiumInputWorkspace");
int neighbours = getProperty("NumberOfNeighbours");
unsigned int uNeighbours = unsigned int(neighbours);
if(sampleWS->getXDimension()->getNBins() != vanadiumWS->getXDimension()->getNBins())
{
throw std::runtime_error("Sample and Vanadium workspaces do not have the same number of bins.");
}
//if(sampleWS->getNumberHistograms() != vanadiumWS->getNumberHistograms())
//{
// throw std::runtime_error("Sample and Vanadium workspaces do not have the same number of historams");
//}

spec2index_map* specToWSIndexMap = vanadiumWS->getSpectrumToWorkspaceIndexMap();

Expand All @@ -73,7 +74,7 @@ namespace Algorithms

// Calculate the average TOF accross all spectra
size_t nHistograms = vanSumTOF_WS->getNumberHistograms();
Progress progress(this,0.01,0.99,nHistograms);
Progress progress(this, 0.01, 0.80,nHistograms);

/// Create an empty workspace with the same dimensions as the integrated vanadium.
MatrixWorkspace_sptr yAvgWS = Mantid::API::WorkspaceFactory::Instance().create(vanSumTOF_WS);
Expand All @@ -91,7 +92,9 @@ namespace Algorithms
std::map<specid_t, double> specIdMap;
PARALLEL_CRITICAL(NearestNeighboursSearch)
{
specIdMap = vanadiumWS->getNeighbours(inSpec, 0.0); //This is not threadsafe!
//CPUTimer tim;
specIdMap = vanadiumWS->getNeighbours(inSpec, uNeighbours); //This is not threadsafe!
// std::cout << tim << " to get nearest neighbours." << std::endl;
}
std::map<specid_t, double>::iterator it = specIdMap.begin();
double spectraSum = 0;
Expand All @@ -116,7 +119,7 @@ namespace Algorithms
vanSumTOF_WS = vanSumTOF_WS/yAvgWS;

//Mask detectors outside of limits
IAlgorithm_sptr constrainAlg = this->createSubAlgorithm("FindDetectorsOutsideLimits", 0.99, 0.991, true, 1);
IAlgorithm_sptr constrainAlg = this->createSubAlgorithm("FindDetectorsOutsideLimits", 0.80, 0.90, true, 1);
constrainAlg->setProperty("InputWorkspace", vanSumTOF_WS);
constrainAlg->setPropertyValue("OutputWorkspace", "ConstrainedWS");
constrainAlg->setProperty("HighThreshold", pow((double)10, (double)300));
Expand All @@ -125,7 +128,7 @@ namespace Algorithms
MatrixWorkspace_sptr constrainedWS = constrainAlg->getProperty("OutputWorkspace");

//Mask detectors outside of limits
IAlgorithm_sptr maskdetectorsAlg = this->createSubAlgorithm("MaskDetectors", 0.991, 1, true, 1);
IAlgorithm_sptr maskdetectorsAlg = this->createSubAlgorithm("MaskDetectors", 0.90, 1, true, 1);
maskdetectorsAlg->setProperty("Workspace", vanSumTOF_WS);
maskdetectorsAlg->setProperty("MaskedWorkspace", constrainedWS);
maskdetectorsAlg->executeAsSubAlg();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class NormaliseByVanadiumTest : public CxxTest::TestSuite
{
using Mantid::API::AnalysisDataService;

MatrixWorkspace_sptr sampleWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(50, 10);
MatrixWorkspace_sptr vanadiumWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(50, 10); //Effectively normalisation by itself.
MatrixWorkspace_sptr sampleWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(5000, 10);
MatrixWorkspace_sptr vanadiumWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(5000, 10); //Effectively normalisation by itself.

NormaliseByVanadium alg;
alg.initialize();
Expand Down Expand Up @@ -132,8 +132,8 @@ class NormaliseByVanadiumTestPeformance : public CxxTest::TestSuite
{
using Mantid::API::AnalysisDataService;

MatrixWorkspace_sptr sampleWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(200, 10);
MatrixWorkspace_sptr vanadiumWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(200, 10); //Effectively normalisation by itself.
MatrixWorkspace_sptr sampleWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(2000, 10);
MatrixWorkspace_sptr vanadiumWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(2000, 10); //Effectively normalisation by itself.

NormaliseByVanadium alg;
alg.initialize();
Expand Down

0 comments on commit 3385ec4

Please sign in to comment.