Skip to content
Snippets Groups Projects
Commit c5302303 authored by Antti Soininen's avatar Antti Soininen
Browse files

IN5: Monitor detector ID 0 -> 100000

Additionally fix the DirectILL* unit tests.

Re #24137
parent 1cc17859
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,7 @@ class DirectILLCollectDataTest(unittest.TestCase):
self.assertEquals(outWS.getNumberHistograms(), inWS.getNumberHistograms() - 1)
ys = outWS.extractY()
originalYs = inWS.extractY()
numpy.testing.assert_almost_equal(ys, originalYs[1:, :] - self._BKG_LEVEL)
numpy.testing.assert_almost_equal(ys, originalYs[:-1, :] - self._BKG_LEVEL)
def testBackgroundOutput(self):
outWSName = 'outWS'
......@@ -90,10 +90,10 @@ class DirectILLCollectDataTest(unittest.TestCase):
inWS = mtd[self._TEST_WS_NAME]
ys = outWS.extractY()
originalYs = inWS.extractY()
numpy.testing.assert_almost_equal(ys, originalYs[1:, :] / duration)
numpy.testing.assert_almost_equal(ys, originalYs[:-1, :] / duration)
es = outWS.extractE()
originalEs = inWS.extractE()
numpy.testing.assert_almost_equal(es, originalEs[1:, :] / duration)
numpy.testing.assert_almost_equal(es, originalEs[:-1, :] / duration)
def testRawWorkspaceOutput(self):
outWSName = 'outWS'
......@@ -112,10 +112,10 @@ class DirectILLCollectDataTest(unittest.TestCase):
rawWS = mtd[rawWSName]
ys = rawWS.extractY()
originalYS = inWS.extractY()
numpy.testing.assert_almost_equal(ys, originalYS[1:, :])
numpy.testing.assert_almost_equal(ys, originalYS[:-1, :])
es = rawWS.extractE()
originalES = inWS.extractE()
numpy.testing.assert_almost_equal(es, originalES[1:, :])
numpy.testing.assert_almost_equal(es, originalES[:-1, :])
xs = rawWS.extractX()
outXS = outWS.extractX()
numpy.testing.assert_almost_equal(xs, outXS)
......@@ -144,13 +144,13 @@ class DirectILLCollectDataTest(unittest.TestCase):
self.assertEquals(outWS.getNumberHistograms(), inWS.getNumberHistograms() - 1)
xs = outWS.extractX()
originalXs = inWS.extractX()
numpy.testing.assert_almost_equal(xs, originalXs[1:, :])
numpy.testing.assert_almost_equal(xs, originalXs[:-1, :])
ys = outWS.extractY()
originalYs = inWS.extractY()
numpy.testing.assert_almost_equal(ys, originalYs[1:, :])
numpy.testing.assert_almost_equal(ys, originalYs[:-1, :])
es = outWS.extractE()
originalEs = inWS.extractE()
numpy.testing.assert_almost_equal(es, originalEs[1:, :])
numpy.testing.assert_almost_equal(es, originalEs[:-1, :])
def testOutputIncidentEnergyWorkspaceWhenEnergyCalibrationIsOff(self):
outWSName = 'outWS'
......
......@@ -10,7 +10,6 @@ import collections
from mantid.api import mtd
import numpy
import numpy.testing
from scipy import constants
from testhelpers import illhelpers, run_algorithm
import unittest
......@@ -175,7 +174,7 @@ class DirectILLReductionTest(unittest.TestCase):
def _groupingTestDetectors(ws):
"""Mask detectors for detector grouping tests."""
indexBegin = 63106 # Detector at L2 and at 2theta = 40.6.
indexBegin = 63105 # Detector at L2 and at 2theta = 40.6.
kwargs = {
'Workspace': ws,
'StartWorkspaceIndex': 0,
......@@ -183,20 +182,18 @@ def _groupingTestDetectors(ws):
'child': True
}
run_algorithm('MaskDetectors', **kwargs)
referenceDetector = ws.getDetector(indexBegin)
reference2Theta1 = ws.detectorTwoTheta(referenceDetector)
referenceDetector = ws.getDetector(indexBegin + 256)
reference2Theta2 = ws.detectorTwoTheta(referenceDetector)
spectrumInfo = ws.spectrumInfo()
reference2Theta1 = spectrumInfo.twoTheta(indexBegin)
reference2Theta2 = spectrumInfo.twoTheta(indexBegin + 256)
mask = list()
tolerance = numpy.deg2rad(0.01)
for i in range(indexBegin + 1, indexBegin + 10000):
det = ws.getDetector(i)
twoTheta = ws.detectorTwoTheta(det)
twoTheta = spectrumInfo.twoTheta(i)
if abs(reference2Theta1 - twoTheta) >= tolerance and abs(reference2Theta2 - twoTheta) >= tolerance:
mask.append(i)
kwargs = {
'Workspace': ws,
'DetectorList': mask,
'WorkspaceIndexList': mask,
'child': True
}
run_algorithm('MaskDetectors', **kwargs)
......
......@@ -94,14 +94,13 @@ def _fillTemplateTOFWorkspace(templateWS, bkgLevel):
xs = numpy.empty(nHistograms*(nBins+1))
ys = numpy.empty(nHistograms*nBins)
es = numpy.empty(nHistograms*nBins)
spectrumInfo = templateWS.spectrumInfo()
instrument = templateWS.getInstrument()
sample = instrument.getSample()
l1 = sample.getDistance(instrument.getSource())
l1 = spectrumInfo.l1()
l2 = float(instrument.getStringParameter('l2')[0])
tofElastic = UnitConversion.run('Energy', 'TOF', E_i, l1, l2, 0.0, DeltaEModeType.Direct, 0.0)
tofBegin = tofElastic - elasticIndex * binWidth
monitor = instrument.getDetector(0)
monitorSampleDistance = sample.getDistance(monitor)
monitorSampleDistance = 0.5
tofElasticMonitor = tofBegin + monitorElasticIndex * binWidth
tofMonitorDetector = UnitConversion.run('Energy', 'TOF', E_i, monitorSampleDistance, l2, 0.0,
DeltaEModeType.Direct, 0.0)
......@@ -121,11 +120,11 @@ def _fillTemplateTOFWorkspace(templateWS, bkgLevel):
ys[yIndexOffset+binIndex] = y
es[yIndexOffset+binIndex] = numpy.sqrt(y)
fillBins(0, tofElasticMonitor, 1623 * elasticPeakHeight, bkgMonitor)
for histogramIndex in range(1, nHistograms):
trueL2 = sample.getDistance(templateWS.getDetector(histogramIndex))
for histogramIndex in range(0, nHistograms - 1):
trueL2 = spectrumInfo.l2(histogramIndex)
trueTOF = UnitConversion.run('Energy', 'TOF', E_i, l1, trueL2, 0.0, DeltaEModeType.Direct, 0.0)
fillBins(histogramIndex, trueTOF, elasticPeakHeight, bkgLevel)
fillBins(nHistograms - 1, tofElasticMonitor, 1623 * elasticPeakHeight, bkgMonitor)
kwargs = {
'DataX': xs,
'DataY': ys,
......@@ -180,7 +179,7 @@ def _fillTemplateTOFWorkspace(templateWS, bkgLevel):
'Workspace': ws,
'ParameterName': 'default-incident-monitor-spectrum',
'ParameterType': 'Number',
'Value': '1',
'Value': str(98305),
'child': True
}
run_algorithm('SetInstrumentParameter', **kwargs)
......@@ -325,6 +324,7 @@ def default_test_detectors(ws):
kwargs = {
'Workspace': ws,
'StartWorkspaceIndex': 512,
'EndWorkspaceIndex': ws.getNumberHistograms() - 2,
'child': True
}
run_algorithm('MaskDetectors', **kwargs)
......
<?xml version='1.0' encoding='ASCII'?>
<instrument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.mantidproject.org/IDF/1.0" last-modified="2018-12-12 12:17:50.421262" name="IN5" valid-from="1900-01-31 23:59:59" valid-to="2100-01-31 23:59:59" xsi:schemaLocation="http://www.mantidproject.org/IDF/1.0 http://schema.mantidproject.org/IDF/1.0/IDFSchema.xsd">
<instrument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.mantidproject.org/IDF/1.0" last-modified="2018-12-12 12:23:39.832773" name="IN5" valid-from="1900-01-31 23:59:59" valid-to="2100-01-31 23:59:59" xsi:schemaLocation="http://www.mantidproject.org/IDF/1.0 http://schema.mantidproject.org/IDF/1.0/IDFSchema.xsd">
<!-- This is the instrument definition file of the IN5 spectrometer at the ILL.
This file was automatically generated by mantidgeometry/ILL/IDF/in5_generateIDF.py
-->
......@@ -39,7 +39,7 @@
<algebra val="cyl-approx"/>
</type>
<idlist idname="monitors">
<id val="0"/>
<id val="100000"/>
</idlist>
<type is="detector" name="standard_pixel">
<cylinder id="pixel_shape">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment