Skip to content

Commit

Permalink
refs #4013. does averaging over nearest neighbours
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Oct 27, 2011
1 parent aa01e43 commit 6332ee1
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 163 deletions.
294 changes: 147 additions & 147 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -338,154 +338,154 @@ set ( INC_FILES
)

set ( TEST_FILES
#test/AddLogDerivativeTest.h
#test/AddSampleLogTest.h
#test/AlignDetectorsTest.h
#test/AlphaCalcTest.h
#test/AnyShapeAbsorptionTest.h
#test/ApplyDetailedBalanceTest.h
#test/ApplyTransmissionCorrectionTest.h
#test/BinaryOperateMasksTest.h
#test/BinaryOperationTest.h
#test/BlendSqTest.h
#test/CalculateEfficiencyTest.h
#test/CalculateTransmissionBeamSpreaderTest.h
#test/CalculateTransmissionTest.h
#test/ChainedOperatorTest.h
#test/ChangeBinOffsetTest.h
#test/ChangeLogTimeTest.h
#test/ChangePulsetimeTest.h
#test/CheckWorkspacesMatchTest.h
#test/ChopDataTest.h
#test/CloneWorkspaceTest.h
#test/CommutativeBinaryOperationTest.h
#test/CompressedRebinTest.h
#test/ConjoinWorkspacesTest.h
#test/ConvertFromDistributionTest.h
#test/ConvertSpectrumAxisTest.h
#test/ConvertToDistributionTest.h
#test/ConvertToEventWorkspaceTest.h
#test/ConvertToHistogramTest.h
#test/ConvertToMatrixWorkspaceTest.h
#test/ConvertToPointDataTest.h
#test/ConvertUnitsTest.h
#test/CopySampleTest.h
#test/CorrectKiKfTest.h
#test/CorrectToFileTest.h
#test/CreateCalFileByNamesTest.h
#test/CreateDummyCalFileTest.h
#test/CreateGroupingWorkspaceTest.h
#test/CreatePSDBleedMaskTest.h
#test/CreatePeaksWorkspaceTest.h
#test/CreateSingleValuedWorkspaceTest.h
#test/CreateWorkspaceTest.h
#test/CropWorkspaceTest.h
#test/CuboidGaugeVolumeAbsorptionTest.h
#test/CylinderAbsorptionTest.h
#test/DampSqTest.h
#test/DeleteWorkspaceTest.h
#test/DetectorEfficiencyCorTest.h
#test/DetectorEfficiencyVariationTest.h
#test/DiffractionEventCalibrateDetectorsTest.h
#test/DiffractionFocussing2Test.h
#test/DiffractionFocussingTest.h
#test/DivideTest.h
#test/DspacemaptoCalTest.h
#test/EditTOFPowderDiffractomerGeometryTest.h
#test/ExponentialCorrectionTest.h
#test/ExponentialTest.h
#test/ExtractFFTSpectrumTest.h
#test/ExtractMaskingTest.h
#test/ExtractSingleSpectrumTest.h
#test/FFTDerivativeTest.h
#test/FFTSmooth2Test.h
#test/FFTTest.h
#test/FilterBadPulsesTest.h
#test/FilterByLogValueTest.h
#test/FilterByTimeTest.h
#test/FindCenterOfMassPosition2Test.h
#test/FindCenterOfMassPositionTest.h
#test/FindDeadDetectorsTest.h
#test/FindDetectorsOutsideLimitsTest.h
#test/FindPeaksTest.h
#test/FlatBackgroundTest.h
#test/FlatPlateAbsorptionTest.h
#test/GeneratePythonScriptTest.h
#test/GetDetectorOffsetsTest.h
#test/GetEiTest.h
#test/GhostCorrectionTest.h
#test/GroupWorkspacesTest.h
#test/HRPDSlabCanAbsorptionTest.h
#test/He3TubeEfficiencyTest.h
#test/IQTransformTest.h
#test/IdentifyNoisyDetectorsTest.h
#test/IntegrationTest.h
#test/InterpolatingRebinTest.h
#test/LogarithmTest.h
#test/MaskBinsTest.h
#test/MedianDetectorTestTest.h
#test/MergeRunsTest.h
#test/MinusTest.h
#test/MonteCarloAbsorptionTest.h
#test/MultipleScatteringCylinderAbsorptionTest.h
#test/MultiplyRangeTest.h
#test/MultiplyTest.h
#test/MuonAsymmetryCalcTest.h
#test/MuonRemoveExpDecayTest.h
#test/NormaliseByCurrentTest.h
test/AddLogDerivativeTest.h
test/AddSampleLogTest.h
test/AlignDetectorsTest.h
test/AlphaCalcTest.h
test/AnyShapeAbsorptionTest.h
test/ApplyDetailedBalanceTest.h
test/ApplyTransmissionCorrectionTest.h
test/BinaryOperateMasksTest.h
test/BinaryOperationTest.h
test/BlendSqTest.h
test/CalculateEfficiencyTest.h
test/CalculateTransmissionBeamSpreaderTest.h
test/CalculateTransmissionTest.h
test/ChainedOperatorTest.h
test/ChangeBinOffsetTest.h
test/ChangeLogTimeTest.h
test/ChangePulsetimeTest.h
test/CheckWorkspacesMatchTest.h
test/ChopDataTest.h
test/CloneWorkspaceTest.h
test/CommutativeBinaryOperationTest.h
test/CompressedRebinTest.h
test/ConjoinWorkspacesTest.h
test/ConvertFromDistributionTest.h
test/ConvertSpectrumAxisTest.h
test/ConvertToDistributionTest.h
test/ConvertToEventWorkspaceTest.h
test/ConvertToHistogramTest.h
test/ConvertToMatrixWorkspaceTest.h
test/ConvertToPointDataTest.h
test/ConvertUnitsTest.h
test/CopySampleTest.h
test/CorrectKiKfTest.h
test/CorrectToFileTest.h
test/CreateCalFileByNamesTest.h
test/CreateDummyCalFileTest.h
test/CreateGroupingWorkspaceTest.h
test/CreatePSDBleedMaskTest.h
test/CreatePeaksWorkspaceTest.h
test/CreateSingleValuedWorkspaceTest.h
test/CreateWorkspaceTest.h
test/CropWorkspaceTest.h
test/CuboidGaugeVolumeAbsorptionTest.h
test/CylinderAbsorptionTest.h
test/DampSqTest.h
test/DeleteWorkspaceTest.h
test/DetectorEfficiencyCorTest.h
test/DetectorEfficiencyVariationTest.h
test/DiffractionEventCalibrateDetectorsTest.h
test/DiffractionFocussing2Test.h
test/DiffractionFocussingTest.h
test/DivideTest.h
test/DspacemaptoCalTest.h
test/EditTOFPowderDiffractomerGeometryTest.h
test/ExponentialCorrectionTest.h
test/ExponentialTest.h
test/ExtractFFTSpectrumTest.h
test/ExtractMaskingTest.h
test/ExtractSingleSpectrumTest.h
test/FFTDerivativeTest.h
test/FFTSmooth2Test.h
test/FFTTest.h
test/FilterBadPulsesTest.h
test/FilterByLogValueTest.h
test/FilterByTimeTest.h
test/FindCenterOfMassPosition2Test.h
test/FindCenterOfMassPositionTest.h
test/FindDeadDetectorsTest.h
test/FindDetectorsOutsideLimitsTest.h
test/FindPeaksTest.h
test/FlatBackgroundTest.h
test/FlatPlateAbsorptionTest.h
test/GeneratePythonScriptTest.h
test/GetDetectorOffsetsTest.h
test/GetEiTest.h
test/GhostCorrectionTest.h
test/GroupWorkspacesTest.h
test/HRPDSlabCanAbsorptionTest.h
test/He3TubeEfficiencyTest.h
test/IQTransformTest.h
test/IdentifyNoisyDetectorsTest.h
test/IntegrationTest.h
test/InterpolatingRebinTest.h
test/LogarithmTest.h
test/MaskBinsTest.h
test/MedianDetectorTestTest.h
test/MergeRunsTest.h
test/MinusTest.h
test/MonteCarloAbsorptionTest.h
test/MultipleScatteringCylinderAbsorptionTest.h
test/MultiplyRangeTest.h
test/MultiplyTest.h
test/MuonAsymmetryCalcTest.h
test/MuonRemoveExpDecayTest.h
test/NormaliseByCurrentTest.h
test/NormaliseByVanadiumTest.h
#test/NormaliseToMonitorTest.h
#test/OneMinusExponentialCorTest.h
#test/PDFFTTest.h
#test/PlotAsymmetryByLogValueTest.h
#test/PlusTest.h
#test/PointByPointVCorrectionTest.h
#test/PoissonErrorsTest.h
#test/PolynomialCorrectionTest.h
#test/PowerLawCorrectionTest.h
#test/PowerTest.h
#test/Q1D2Test.h
#test/Q1DTest.h
#test/Q1DWeightedTest.h
#test/QxyTest.h
#test/RayTracerTesterTest.h
#test/ReadGroupsFromFileTest.h
#test/RealFFTTest.h
#test/Rebin2DTest.h
#test/RebinTest.h
#test/RebinToWorkspaceTest.h
#test/RebunchTest.h
#test/RegroupTest.h
#test/RemoveBinsTest.h
#test/RemoveLowResTOFTest.h
#test/RemovePromptPulseTest.h
#test/RenameWorkspaceTest.h
#test/ReplaceSpecialValuesTest.h
#test/ScaleTest.h
#test/ScaleXTest.h
#test/ShiftLogTimeTest.h
#test/SmoothDataTest.h
#test/SmoothNeighboursTest.h
#test/SofQW2Test.h
#test/SofQWTest.h
#test/SolidAngleTest.h
#test/SortEventsTest.h
#test/SpatialGroupingTest.h
#test/SphericalAbsorptionTest.h
#test/StripPeaksTest.h
#test/StripVanadiumPeaks2Test.h
#test/StripVanadiumPeaksTest.h
#test/SumNeighboursTest.h
#test/SumRowColumnTest.h
#test/SumSpectraTest.h
#test/TransposeTest.h
#test/UnGroupWorkspacesTest.h
#test/UnaryOperationTest.h
#test/UnwrapSNSTest.h
#test/UnwrapTest.h
#test/WeightedMeanTest.h
#test/WorkspaceCreationHelperTest.h
#test/WorkspaceGroupTest.h
test/NormaliseToMonitorTest.h
test/OneMinusExponentialCorTest.h
test/PDFFTTest.h
test/PlotAsymmetryByLogValueTest.h
test/PlusTest.h
test/PointByPointVCorrectionTest.h
test/PoissonErrorsTest.h
test/PolynomialCorrectionTest.h
test/PowerLawCorrectionTest.h
test/PowerTest.h
test/Q1D2Test.h
test/Q1DTest.h
test/Q1DWeightedTest.h
test/QxyTest.h
test/RayTracerTesterTest.h
test/ReadGroupsFromFileTest.h
test/RealFFTTest.h
test/Rebin2DTest.h
test/RebinTest.h
test/RebinToWorkspaceTest.h
test/RebunchTest.h
test/RegroupTest.h
test/RemoveBinsTest.h
test/RemoveLowResTOFTest.h
test/RemovePromptPulseTest.h
test/RenameWorkspaceTest.h
test/ReplaceSpecialValuesTest.h
test/ScaleTest.h
test/ScaleXTest.h
test/ShiftLogTimeTest.h
test/SmoothDataTest.h
test/SmoothNeighboursTest.h
test/SofQW2Test.h
test/SofQWTest.h
test/SolidAngleTest.h
test/SortEventsTest.h
test/SpatialGroupingTest.h
test/SphericalAbsorptionTest.h
test/StripPeaksTest.h
test/StripVanadiumPeaks2Test.h
test/StripVanadiumPeaksTest.h
test/SumNeighboursTest.h
test/SumRowColumnTest.h
test/SumSpectraTest.h
test/TransposeTest.h
test/UnGroupWorkspacesTest.h
test/UnaryOperationTest.h
test/UnwrapSNSTest.h
test/UnwrapTest.h
test/WeightedMeanTest.h
test/WorkspaceCreationHelperTest.h
test/WorkspaceGroupTest.h
)

set(SRC_UNITY_IGNORE_FILES src/AlignDetectors.cpp
Expand Down
49 changes: 36 additions & 13 deletions Code/Mantid/Framework/Algorithms/src/NormaliseByVanadium.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "MantidAlgorithms/NormaliseByVanadium.h"
#include "MantidAPI/WorkspaceValidators.h"
#include "MantidAPI/WorkspaceOpOverloads.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidKernel/Exception.h"

using namespace Mantid::Kernel;
using namespace Mantid::API;
Expand Down Expand Up @@ -50,6 +52,8 @@ namespace Algorithms
{
MatrixWorkspace_sptr sampleWS = getProperty("SampleInputWorkspace");
MatrixWorkspace_sptr vanadiumWS = getProperty("VanadiumInputWorkspace");

spec2index_map* specToWSIndexMap = vanadiumWS->getSpectrumToWorkspaceIndexMap();

// Integrate across all bins
IAlgorithm_sptr integrateAlg = this->createSubAlgorithm("Integration", 0, 1, true, 1);
Expand All @@ -60,24 +64,43 @@ namespace Algorithms
MatrixWorkspace_sptr vanSumTOF_WS = integrateAlg->getProperty("OutputWorkspace");

// Calculate the average TOF accross all spectra
size_t nSpectra = vanSumTOF_WS->getNumberHistograms();
Progress progress(this,0.0,1.0,nSpectra);
double spectraSum = 0;
//OPENMP
for(size_t i = 0; i < nSpectra; i++)
size_t nHistograms = vanSumTOF_WS->getNumberHistograms();
Progress progress(this,0.0,1.0,nHistograms);

/// Create an empty workspace with the same dimensions as the integrated vanadium.
MatrixWorkspace_sptr yAvgWS = Mantid::API::WorkspaceFactory::Instance().create(vanSumTOF_WS);

/*
Find the nearest neighbours for the spectrum and use those to calculate an average (9 points)
*/
//PARALLEL_FOR2(yAvgWS, vanSumTOF_WS)
for(int i = 0; i < int(nHistograms); i++)
{
spectraSum += vanSumTOF_WS->readY(i)[0];
//PARALLEL_START_INTERUPT_REGION
try
{
Mantid::Geometry::IDetector_const_sptr idet = vanadiumWS->getDetector(i);
std::map<specid_t, double> specIdMap = vanadiumWS->getNeighbours(idet.get());
std::map<specid_t, double>::iterator it = specIdMap.begin();
double spectraSum = 0;
while(it != specIdMap.end())
{
spectraSum += vanSumTOF_WS->readY((*specToWSIndexMap)[it->first])[0];
it++;
}
spectraSum += vanSumTOF_WS->readY(i)[0];
yAvgWS->dataY(i)[0] = spectraSum/(specIdMap.size() + 1);
}
catch(Kernel::Exception::NotFoundError&)
{
}
progress.report();
//PARALLEL_END_INTERUPT_REGION
}
double yavg = spectraSum/nSpectra;
//PARALLEL_CHECK_INTERUPT_REGION

// Normalise the integrated TOFs
IAlgorithm_sptr createDenominatorAlg = this->createSubAlgorithm("CreateSingleValuedWorkspace", 0, 1, true, 1);
createDenominatorAlg->setProperty("DataValue", yavg);
createDenominatorAlg->setPropertyValue("OutputWorkspace", "denominator");
createDenominatorAlg->executeAsSubAlg();
MatrixWorkspace_sptr denominatorWS = createDenominatorAlg->getProperty("OutputWorkspace");
vanSumTOF_WS = vanSumTOF_WS/denominatorWS;
vanSumTOF_WS = vanSumTOF_WS/yAvgWS;

//Mask detectors outside of limits
IAlgorithm_sptr constrainAlg = this->createSubAlgorithm("FindDetectorsOutsideLimits", 0, 1, true, 1);
Expand Down

0 comments on commit 6332ee1

Please sign in to comment.