diff --git a/Code/Mantid/Framework/Algorithms/CMakeLists.txt b/Code/Mantid/Framework/Algorithms/CMakeLists.txt
index a448a3324258..999f3ae89e94 100644
--- a/Code/Mantid/Framework/Algorithms/CMakeLists.txt
+++ b/Code/Mantid/Framework/Algorithms/CMakeLists.txt
@@ -18,6 +18,7 @@ set ( SRC_FILES
src/ApplyTransmissionCorrection.cpp
src/AsymmetryCalc.cpp
src/AverageLogData.cpp
+ src/BackgroundHelper.cpp
src/BinaryOperateMasks.cpp
src/BinaryOperation.cpp
src/CalMuonDeadTime.cpp
@@ -266,6 +267,7 @@ set ( INC_FILES
inc/MantidAlgorithms/ApplyTransmissionCorrection.h
inc/MantidAlgorithms/AsymmetryCalc.h
inc/MantidAlgorithms/AverageLogData.h
+ inc/MantidAlgorithms/BackgroundHelper.h
inc/MantidAlgorithms/BinaryOperateMasks.h
inc/MantidAlgorithms/BinaryOperation.h
inc/MantidAlgorithms/CalMuonDeadTime.h
@@ -526,6 +528,7 @@ set ( TEST_FILES
ApplyTransmissionCorrectionTest.h
AsymmetryCalcTest.h
AverageLogDataTest.h
+ BackgroundHelperTest.h
BinaryOperateMasksTest.h
BinaryOperationTest.h
CalculateEfficiencyTest.h
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/BackgroundHelper.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/BackgroundHelper.h
new file mode 100644
index 000000000000..fa4aeba4beb5
--- /dev/null
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/BackgroundHelper.h
@@ -0,0 +1,55 @@
+#ifndef MANTID_ALGORITHM_BACKGROUNDHELPER_H_
+#define MANTID_ALGORITHM_BACKGROUNDHELPER_H_
+
+
+#include "MantidKernel/Unit.h"
+#include "MantidKernel/cow_ptr.h"
+
+#include "MantidAPI/DllConfig.h"
+#include "MantidAPI/MatrixWorkspace.h"
+
+namespace Mantid
+{
+namespace Algorithms
+{
+/** Class helping to remove constant (and possibly non-constant after simple modification) background calculated in TOF units
+ from a matrix workspace, expressed in units, different from TOF.
+
+ @date 26/10/2014
+
+ Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+ This file is part of Mantid.
+
+ Mantid is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Mantid is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+ File change history is stored at: .
+ Code Documentation is available at:
+*/
+
+ class DLLExport BackgroundHelper
+ {
+ public:
+ BackgroundHelper():m_emode(0){};
+ void initialize(const API::MatrixWorkspace_const_sptr &bkgWS,const API::MatrixWorkspace_sptr &sourceWS,int emode);
+
+ void removeBackground(int hist,const MantidVec &XValues,MantidVec &y_data,MantidVec &e_data);
+ private:
+ int m_emode;
+
+ };
+
+}
+}
+#endif
\ No newline at end of file
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Rebin.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Rebin.h
index 87b5924515bf..1eee184947de 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Rebin.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Rebin.h
@@ -5,6 +5,7 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
+#include "MantidAlgorithms/BackgroundHelper.h"
namespace Mantid
{
@@ -51,9 +52,9 @@ class DLLExport Rebin : public API::Algorithm
{
public:
/// Default constructor
- Rebin() : API::Algorithm() {};
+ Rebin() : API::Algorithm(),m_BackgroundHelper() {};
/// Destructor
- virtual ~Rebin() {};
+ virtual ~Rebin(){};
/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const { return "Rebin";}
///Summary of algorithms purpose
@@ -87,6 +88,8 @@ class DLLExport Rebin : public API::Algorithm
private:
// method to check if removing background is requested and possible
API::MatrixWorkspace_const_sptr checkRemoveBackgroundParameters(const API::MatrixWorkspace_sptr &inputWS,int &eMode, bool PreserveEvents);
+ // class responsible for background removal
+ BackgroundHelper m_BackgroundHelper;
};
diff --git a/Code/Mantid/Framework/Algorithms/src/BackgroundHelper.cpp b/Code/Mantid/Framework/Algorithms/src/BackgroundHelper.cpp
new file mode 100644
index 000000000000..12d7955fce2f
--- /dev/null
+++ b/Code/Mantid/Framework/Algorithms/src/BackgroundHelper.cpp
@@ -0,0 +1,19 @@
+#include "MantidAlgorithms/BackgroundHelper.h"
+
+
+namespace Mantid
+{
+namespace Algorithms
+{
+
+
+void BackgroundHelper::initialize(const API::MatrixWorkspace_const_sptr &bkgWS,const API::MatrixWorkspace_sptr &sourceWS,int emode)
+{
+}
+
+void BackgroundHelper::removeBackground(int hist,const MantidVec &XValues,MantidVec &y_data,MantidVec &e_data)
+{
+}
+
+} // end API
+} // end Mantid
diff --git a/Code/Mantid/Framework/Algorithms/src/Rebin.cpp b/Code/Mantid/Framework/Algorithms/src/Rebin.cpp
index ba3d4315f27f..780f1ccbed22 100644
--- a/Code/Mantid/Framework/Algorithms/src/Rebin.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/Rebin.cpp
@@ -105,11 +105,11 @@ namespace Mantid
vsValidator->add();
declareProperty(new WorkspaceProperty<>("FlatBkgWorkspace","",Direction::Input,API::PropertyMode::Optional,vsValidator),
"An optional histogram workspace in the units of TOF defined background for removal during rebinning."
- "The workspace has to have single value or contain the same number of spectra as the \"InputWorkspace\" and single Y value per each spectra,
- "representing flat background in this time bin. "
+ "The workspace has to have single value or contain the same number of spectra as the \"InputWorkspace\" and single Y value per each spectra,"
+ "representing flat background in the background time region. "
"If such workspace is present, the value of the flat background provided by this workspace is removed "
"from each spectra of the rebinned workspace. This works for histogram and event workspace when events are not retained "
- "but actually useful mainly for removing background from event workspace in the units different from TOF.");
+ "but actually useful mainly for removing background while rebinning an event workspace in the units different from TOF.");
std::vector dE_modes = Kernel::DeltaEMode().availableTypes();
declareProperty("dEAnalysisMode",dE_modes[Kernel::DeltaEMode::Direct],boost::make_shared(dE_modes),
@@ -145,9 +145,13 @@ namespace Mantid
// workspace independent determination of length
const int histnumber = static_cast(inputWS->getNumberHistograms());
+ //-- Flat Background removal ----------------------------
int eMode; // in convert units emode is still integer
API::MatrixWorkspace_const_sptr bkgWS = checkRemoveBackgroundParameters(inputWS,eMode,PreserveEvents);
const bool remove_background = bool(bkgWS);
+ if(remove_background)
+ m_BackgroundHelper.initialize(bkgWS,inputWS,eMode);
+ //-------------------------------------------------------
bool fullBinsOnly = getProperty("FullBinsOnly");
@@ -219,6 +223,11 @@ namespace Mantid
MantidVec y_data, e_data;
// The EventList takes care of histogramming.
el.generateHistogram(*XValues_new, y_data, e_data);
+ if(remove_background)
+ {
+ m_BackgroundHelper.removeBackground(i,*XValues_new,y_data,e_data);
+ }
+
//Copy the data over.
outputWS->dataY(i).assign(y_data.begin(), y_data.end());
@@ -279,7 +288,7 @@ namespace Mantid
{
PARALLEL_START_INTERUPT_REGION
// get const references to input Workspace arrays (no copying)
- const MantidVec& XValues = inputWS->readX(hist);
+ const MantidVec& XValues = inputWS->readX(hist);
const MantidVec& YValues = inputWS->readY(hist);
const MantidVec& YErrors = inputWS->readE(hist);
@@ -290,6 +299,10 @@ namespace Mantid
// output data arrays are implicitly filled by function
try {
VectorHelper::rebin(XValues,YValues,YErrors,*XValues_new,YValues_new,YErrors_new, dist);
+ if(remove_background)
+ {
+ m_BackgroundHelper.removeBackground(hist,*XValues_new,YValues_new,YErrors_new);
+ }
} catch (std::exception& ex)
{
g_log.error() << "Error in rebin function: " << ex.what() << std::endl;
diff --git a/Code/Mantid/Framework/Algorithms/test/BackgroundHelperTest.h b/Code/Mantid/Framework/Algorithms/test/BackgroundHelperTest.h
new file mode 100644
index 000000000000..13975f25a378
--- /dev/null
+++ b/Code/Mantid/Framework/Algorithms/test/BackgroundHelperTest.h
@@ -0,0 +1,38 @@
+#ifndef BACKGROUDHELPER_TEST_H_
+#define BACKGROUDHELPER_TEST_H_
+
+#include
+
+#include "MantidAlgorithms/BackgroundHelper.h"
+
+
+
+class BackgroundHelperTest : public CxxTest::TestSuite
+{
+public:
+
+ // This pair of boilerplate methods prevent the suite being created statically
+ // This means the constructor isn't called when running other tests
+ static BackgroundHelperTest *createSuite() { return new BackgroundHelperTest(); }
+ static void destroySuite( BackgroundHelperTest *suite ) { delete suite; }
+
+ BackgroundHelperTest()
+ {
+ }
+
+ ~BackgroundHelperTest()
+ {
+ }
+
+ void testBackgroundInit()
+ {
+ }
+
+private:
+
+
+};
+
+
+
+#endif /*ALGORITHMTEST_H_*/