Skip to content

Commit

Permalink
refs #10384 Framework class for background removal
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Oct 27, 2014
1 parent 7176a1e commit e2e9a1b
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -526,6 +528,7 @@ set ( TEST_FILES
ApplyTransmissionCorrectionTest.h
AsymmetryCalcTest.h
AverageLogDataTest.h
BackgroundHelperTest.h
BinaryOperateMasksTest.h
BinaryOperationTest.h
CalculateEfficiencyTest.h
Expand Down
@@ -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 <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

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
7 changes: 5 additions & 2 deletions Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Rebin.h
Expand Up @@ -5,6 +5,7 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidAlgorithms/BackgroundHelper.h"

namespace Mantid
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

};

Expand Down
19 changes: 19 additions & 0 deletions 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
21 changes: 17 additions & 4 deletions Code/Mantid/Framework/Algorithms/src/Rebin.cpp
Expand Up @@ -105,11 +105,11 @@ namespace Mantid
vsValidator->add<HistogramValidator>();
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<std::string> dE_modes = Kernel::DeltaEMode().availableTypes();
declareProperty("dEAnalysisMode",dE_modes[Kernel::DeltaEMode::Direct],boost::make_shared<Kernel::StringListValidator>(dE_modes),
Expand Down Expand Up @@ -145,9 +145,13 @@ namespace Mantid
// workspace independent determination of length
const int histnumber = static_cast<int>(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");

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions Code/Mantid/Framework/Algorithms/test/BackgroundHelperTest.h
@@ -0,0 +1,38 @@
#ifndef BACKGROUDHELPER_TEST_H_
#define BACKGROUDHELPER_TEST_H_

#include <cxxtest/TestSuite.h>

#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_*/

0 comments on commit e2e9a1b

Please sign in to comment.