Skip to content

Commit

Permalink
refs #10384 fixed multithreading mode
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Oct 28, 2014
1 parent 64cdb19 commit 49d47e5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
10 changes: 6 additions & 4 deletions Code/Mantid/Framework/Algorithms/src/BackgroundHelper.cpp
Expand Up @@ -68,6 +68,7 @@ namespace Mantid
*/
void BackgroundHelper::removeBackground(int nHist,const MantidVec &XValues,MantidVec &y_data,MantidVec &e_data)const
{

double dtBg,ErrSq,IBg;
if(m_singleValueBackground)
{
Expand All @@ -92,12 +93,13 @@ namespace Mantid
double twoTheta = m_wkWS->detectorTwoTheta(detector);
double L2 = detector->getDistance(*m_Sample);
double delta(std::numeric_limits<double>::quiet_NaN());
//
m_WSUnit->initialize(m_L1, L2,twoTheta, m_Emode, m_Efix,delta);
double tof1 = m_WSUnit->singleToTOF(XValues[0]);
// clone unit conversion to avoid multithreading issues
auto unitCong = m_WSUnit->clone();
unitCong->initialize(m_L1, L2,twoTheta, m_Emode, m_Efix,delta);
double tof1 = unitCong->singleToTOF(XValues[0]);
for(size_t i=0;i<y_data.size();i++)
{
double tof2=m_WSUnit->singleToTOF(XValues[i+1]);
double tof2=unitCong->singleToTOF(XValues[i+1]);
double Jack = std::fabs((tof2-tof1)/dtBg);
double normBkgrnd = IBg*Jack;
tof1=tof2;
Expand Down
47 changes: 45 additions & 2 deletions Code/Mantid/docs/source/algorithms/Rebin-v1.rst
Expand Up @@ -83,7 +83,7 @@ Remove Background during rebinning options
##########################################

These options allow you to remove flat background, defined by the a single bin
historgram workspace with X-axis in the units of TOF from a workspace in any
histogram workspace with X-axis in the units of TOF from a workspace in any
units with known conversion into TOF. The background removal occurs during rebinning

These options are especially useful during reduction
Expand Down Expand Up @@ -186,10 +186,53 @@ presented on the following picture:

.. image:: /images/BgRemoval.png

Blue line on this image represents the results, obatined using Rebin with background removal obtained using the following script::
Blue line on this image represents the results, obtained using Rebin with background removal. The results produced using
the script below and shifted by one to show that there is another result plotted on the image, as both results
are identical::

from mantid.simpleapi import *
from mantid import config
import numpy as np
import sys
import os
maps_dir = '/home/user/InstrumentFiles/let/'
data_dir ='/home/user/results'
ref_data_dir = '/home/user/SystemTests/AnalysisTests/ReferenceResults'
config.setDataSearchDirs('{0};{1};{2}'.format(data_dir,maps_dir,ref_data_dir))
config['defaultsave.directory'] = data_dir # folder to save resulting spe/nxspe files. Defaults are in
# the name of a workspace containing background
filename = 'LET0007438'
groupedFilename = filename+'rings';
#
Ei= 25
e_min = -20
e_max = 20
dE = 0.1
bgRange = [15000,18000]


if not(groupedFilename in mtd):
Load(Filename=filename+'.nxs', OutputWorkspace=filename, LoadMonitors=True)
GroupDetectors(InputWorkspace=filename, OutputWorkspace=groupedFilename , MapFile='LET_one2one_123.map', Behaviour='Average')
if not('Bg' in mtd):
Bg=Rebin(InputWorkspace=groupedFilename, Params=[bgRange[0],bgRange[1]-bgRange[0],bgRange[1]],PreserveEvents=False)
else:
Bg = mtd['Bg']
if 'resultEtransf' in mtd:
resultEtransf = mtd['resultEtransf']
else:
resultEtransf = ConvertUnits(groupedFilename,'DeltaE',Emode='Direct',EFixed=Ei)
noBgWorkspace= Rebin(InputWorkspace=resultEtransf, Params=[e_min,dE,e_max],PreserveEvents=False,FlatBkgWorkspace='Bg',EMode='Direct')
nHist = Bg.getNumberHistograms()
removedBkgSum = SumSpectra(noBgWorkspace ,0,nHist);

.. _rebin-usage:

Usage
Expand Down
Binary file modified Code/Mantid/docs/source/images/BgRemoval.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 49d47e5

Please sign in to comment.