Skip to content

Commit

Permalink
Re #10384 moved existing tests separately from Rebin&BackgroundHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Oct 31, 2014
1 parent 0cf37b6 commit d26a2c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 38 deletions.
@@ -1,5 +1,5 @@
#ifndef MANTID_ALGORITHMS_REBIN_H_
#define MANTID_ALGORITHMS_REBIN_H_
#ifndef MANTID_ALGORITHMS_REMOVEBACKGROUND_H_
#define MANTID_ALGORITHMS_REMOVEBACKGROUND_H_

//----------------------------------------------------------------------
// Includes
Expand Down Expand Up @@ -35,16 +35,18 @@ namespace Mantid
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

/**Class actually performing background removal from a workspace spectra */
class DLLExport BackgroundHelper
{
public:
BackgroundHelper();
~BackgroundHelper();

void initialize(const API::MatrixWorkspace_const_sptr &bkgWS,const API::MatrixWorkspace_sptr &sourceWS,
int emode,int nTreads=1,bool inPlace=true);
int emode,Kernel::Logger *pLog=NULL,int nTreads=1,bool inPlace=true);
void removeBackground(int hist,const MantidVec &XValues,MantidVec &y_data,MantidVec &e_data,
int tread_num=0,Kernel::Logger *pLog=NULL)const;
int tread_num=0)const;

private:
//vector of pointers to the units conversion class for the working workspace;
Expand All @@ -55,6 +57,8 @@ namespace Mantid
// shared pointer to the workspace where background should be removed
API::MatrixWorkspace_const_sptr m_wkWS;

// logger from the hosting algorithm
Kernel::Logger *m_pgLog;
// perform background removal in-place
bool m_inPlace;

Expand Down
37 changes: 14 additions & 23 deletions Code/Mantid/Framework/Algorithms/src/RemoveBackground.cpp
Expand Up @@ -95,13 +95,6 @@ namespace Mantid

// Removing background in-place
bool inPlace = (inputWS == outputWS);
//
int nThreads = omp_get_max_threads();
m_BackgroundHelper.initialize(bkgWksp,inputWS,eMode,nThreads,inPlace);




// workspace independent determination of length
const int histnumber = static_cast<int>(inputWS->getNumberHistograms());

Expand All @@ -111,34 +104,31 @@ namespace Mantid
outputWS = API::WorkspaceFactory::Instance().create(inputWS);
}


//
int nThreads = PARALLEL_NUMBER_OF_THREADS;
m_BackgroundHelper.initialize(bkgWksp,inputWS,eMode,&g_log,nThreads,inPlace);

Progress prog(this,0.0,1.0,histnumber);
PARALLEL_FOR2(inputWS,outputWS)
for (int hist=0; hist < histnumber;++hist)
{
PARALLEL_START_INTERUPT_REGION
// get const references to input Workspace arrays (no copying)
const MantidVec& XValues = outputWS->readX(hist);
// get const references to input Workspace arrays (no copying)
const MantidVec& XValues = outputWS->readX(hist);
MantidVec& YValues = outputWS->dataY(hist);
MantidVec& YErrors = outputWS->dataE(hist);

// output data arrays are implicitly filled by function
int id = omp_get_thread_num();
m_BackgroundHelper.removeBackground(hist,XValues,YValues,YErrors,id,&g_log);
int id = PARALLEL_THREAD_NUMBER;
m_BackgroundHelper.removeBackground(hist,XValues,YValues,YErrors,id);

prog.report(name());
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION



// Assign it to the output workspace property
setProperty("OutputWorkspace",outputWS);



return;
}
//-------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -148,14 +138,15 @@ namespace Mantid
BackgroundHelper::BackgroundHelper():
m_WSUnit(),
m_bgWs(),m_wkWS(),
m_pgLog(NULL),
m_inPlace(true),
m_singleValueBackground(false),
m_NBg(0),m_dtBg(1), //m_ErrSq(0),
m_Emode(0),
m_L1(0),m_Efix(0),
m_Sample()
{};
/// Desctructoe
/// Destructor
BackgroundHelper::~BackgroundHelper()
{
this->deleteUnitsConverters();
Expand All @@ -182,12 +173,12 @@ namespace Mantid
@param nThreads -- number of threads to be used for background removal
@param inPlace -- if the background removal occurs from the existing workspace or target workspace has to be cloned.
*/
void BackgroundHelper::initialize(const API::MatrixWorkspace_const_sptr &bkgWS,const API::MatrixWorkspace_sptr &sourceWS,int emode,int nThreads,bool inPlace)
void BackgroundHelper::initialize(const API::MatrixWorkspace_const_sptr &bkgWS,const API::MatrixWorkspace_sptr &sourceWS,int emode,Kernel::Logger *pLog,int nThreads,bool inPlace)
{
m_bgWs = bkgWS;
m_wkWS = sourceWS;
m_Emode = emode;

m_pgLog = pLog;

std::string bgUnits = bkgWS->getAxis(0)->unit()->unitID();
if(bgUnits!="TOF")
Expand Down Expand Up @@ -235,7 +226,7 @@ namespace Mantid
* @param e_data -- the spectra errors
* @param threadNum -- number of thread doing conversion (by default 0, single thread)
*/
void BackgroundHelper::removeBackground(int nHist,const MantidVec &XValues,MantidVec &y_data,MantidVec &e_data,int threadNum,Kernel::Logger *pLog)const
void BackgroundHelper::removeBackground(int nHist,const MantidVec &XValues,MantidVec &y_data,MantidVec &e_data,int threadNum)const
{

double dtBg,IBg;
Expand Down Expand Up @@ -297,8 +288,8 @@ namespace Mantid
catch(...)
{
// no background removal for this spectra as it does not have a detector or other reason
if(pLog)
pLog->debug()<<" Can not remove background for the spectra with number (id)"<<nHist;
if(m_pgLog)
m_pgLog->debug()<<" Can not remove background for the spectra with number (id)"<<nHist;
}

}
Expand Down
21 changes: 10 additions & 11 deletions Code/Mantid/Framework/Algorithms/test/RemoveBackgroundTest.h
@@ -1,32 +1,30 @@
#ifndef BACKGROUDHELPER_TEST_H_
#define BACKGROUDHELPER_TEST_H_
#ifndef REMOVE_BACKGROUD_TEST_H_
#define REMOVE_BACKGROUD_TEST_H_

#include <cxxtest/TestSuite.h>

#include "MantidAlgorithms/BackgroundHelper.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"

#include "MantidAlgorithms/RemoveBackground.h"
#include "MantidAlgorithms/Rebin.h"
#include "MantidAlgorithms/ConvertUnits.h"
#include "MantidAlgorithms/CalculateFlatBackground.h"

#include "MantidTestHelpers/WorkspaceCreationHelper.h"
using namespace Mantid;

class BackgroundHelperTest : public CxxTest::TestSuite
class RemoveBackgroundTest : 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; }
static RemoveBackgroundTest *createSuite() { return new RemoveBackgroundTest(); }
static void destroySuite( RemoveBackgroundTest *suite ) { delete suite; }

BackgroundHelperTest()
RemoveBackgroundTest()
{

DataObjects::Workspace2D_sptr theWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(1, 15000);

Algorithms::Rebin rebinner;
std::string wsName = theWS->getName();
if(wsName.empty())
{
Expand All @@ -37,6 +35,7 @@ class BackgroundHelperTest : public CxxTest::TestSuite

API::AnalysisDataService::Instance().addOrReplace(wsName,theWS);

Algorithms::Rebin rebinner;
rebinner.initialize();
rebinner.setPropertyValue("InputWorkspace",theWS->getName());
rebinner.setPropertyValue("OutputWorkspace","Background");
Expand Down Expand Up @@ -78,7 +77,7 @@ class BackgroundHelperTest : public CxxTest::TestSuite

}

~BackgroundHelperTest()
~RemoveBackgroundTest()
{
BgWS.reset();
SourceWS.reset();
Expand Down

0 comments on commit d26a2c5

Please sign in to comment.