Skip to content

Commit

Permalink
Merge pull request #14248 from mantidproject/14241_add_bin_witdth_to_…
Browse files Browse the repository at this point in the history
…q_resolution_calculation

Everything was fine when completing test procedure, no errors produce so I'm happy to merge this.
  • Loading branch information
MattKing06 committed Nov 4, 2015
2 parents 9bc51fb + ec06559 commit d7ade86
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 22 deletions.
7 changes: 6 additions & 1 deletion Framework/Algorithms/src/Q1D2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ void Q1D2::exec() {
EOutTo2[bin] += (*EIn) * (*EIn);
normError2[bin] += *normETo2s;
if (useQResolution) {
qResolutionOut[bin] += (*YIn) * (*QResIn);
auto QBin = (QOut[bin + 1] - QOut[bin]);
// Here we need to take into account the Bin width and the count
// weigthing. The
// formula should be YIN* sqrt(QResIn^2 + (QBin/sqrt(12))^2)
qResolutionOut[bin] +=
(*YIn) * std::sqrt((*QResIn) * (*QResIn) + QBin * QBin / 12.0);
}
}
}
Expand Down
33 changes: 22 additions & 11 deletions Framework/Algorithms/test/Q1D2Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class Q1D2Test : public CxxTest::TestSuite {
// Arrange
Mantid::API::MatrixWorkspace_sptr qResolution, alteredInput;
const double value1 = 1;
const double value2 = 2;
const double value2 = 1;
createQResolutionWorkspace(qResolution, alteredInput, m_inputWS, value1,
value2);

Expand All @@ -409,7 +409,7 @@ class Q1D2Test : public CxxTest::TestSuite {
Q1D.setProperty("WavelengthAdj", m_wavNorm);
Q1D.setProperty("PixelAdj", m_pixel);
Q1D.setPropertyValue("OutputWorkspace", outputWS);
Q1D.setPropertyValue("OutputBinning", "0.1,-0.02,0.5");
Q1D.setPropertyValue("OutputBinning", "0.5,0.5,10.0");
Q1D.setProperty("QResolution", qResolution);
Q1D.setProperty("OutputParts", true);

Expand All @@ -430,22 +430,33 @@ class Q1D2Test : public CxxTest::TestSuite {
outputWS + "_sumOfCounts")))

TSM_ASSERT("Should have the x error flag set", result->hasDx(0));
// That output will be SUM_i(Yin_i*QRES_in_i)/(SUM_i(Y_in_i)) for each q
// That output will be
// SUM_i(Yin_i*sqrt(QRES_in_i^2 + *QBinWidth^2/sqrt(12)^2))/(SUM_i(Y_in_i))
// for each q
// value
// In our test workspace we set QRes_in_1 to 1, this means that all DX
// values should be SUM_i(Y_in_i)/(SUM_i(Y_in_i))
// which is either 1 or 0. It can be 0 if no data falls into this bin. We
// make sure that there is at least one bin
// with a count of 1
// values should be SUM_i(Y_in_i*sqrt((1+ QBinWidth^2/12)/(SUM_i(Y_in_i))
// which is either sqrt(1 + 0.5^2/12) or 0. It can be 0 if no data falls
// into this
// bin. We make sure that there is at least one bin with a count
// of sqrt(1 + 0.5^2/12) ~ 1.01036297108
auto &dataDX = result->dataDx(0);
unsigned int counter = 0;
for (auto it = dataDX.begin(); it != dataDX.end(); ++it) {
if (*it == 1.0) {

// Since we are dealing with a float it can be difficult to compare
// our value with sqrt(1 + 0.5^2/12). Hence it is enough for us to confirm
// that the values lie in an interval around this value
auto isZeroValue = *it == 0.0;
auto isCloseToZeroPoint1DividedByRootTwelve =
(*it > 1.01035) && (*it < 1.01037);
if (isCloseToZeroPoint1DividedByRootTwelve) {
counter++;
}
// Make sure that the value is either 1 or 0
TSM_ASSERT("The DX value should be either 1 or 0",
(*it == 1.0) || (*it == 0.0));

// Make sure that the value is either sqrt(1 + 0.5^2/12) or 0
TSM_ASSERT("The DX value should be either sqrt(1 + 0.5^2/12) or 0",
isCloseToZeroPoint1DividedByRootTwelve || isZeroValue);
}
TSM_ASSERT("There should be at least one bin which is not 0", counter > 0);

Expand Down
3 changes: 3 additions & 0 deletions MantidQt/CustomInterfaces/src/SANSRunWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,9 @@ bool SANSRunWindow::loadUserFile() {
// Set the beam finder specific settings
setBeamFinderDetails();
// get the scale factor1 for the beam centre to scale it correctly
dbl_param =
runReduceScriptFunction(
"print i.ReductionSingleton().get_beam_center('rear')[0]").toDouble();
double dbl_paramsf =
runReduceScriptFunction(
"print i.ReductionSingleton().get_beam_center_scale_factor1()")
Expand Down
32 changes: 22 additions & 10 deletions scripts/SANS/ISISCommandInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,19 @@ def AddRuns(runs, instrument ='sans2d', saveAsEvent=False, binning = "Monitors",
Method to expose the add_runs functionality for custom scripting.
@param runs: a list with the requested run numbers
@param instrument: the name of the selected instrument
@param binning: the where to get the binnings from. This can either be "Monitors
@param saveAsEvent: when adding event-type data, then this can be stored as event-type data
@param binning: where to get the binnings from. This is relevant when adding Event-type data.
The property can be set to "Monitors" in order to emulate the binning of the monitors or to a
string list with the same format that is used for the Rebin algorithm. This property is ignored
when saving as event data.
@param isOverlay: sets if the the overlay mechanism should be used when the saveAsEvent flag is set
@param time_shifts: provides additional time shifts if the isOverlay flag is specified. The time shifts are specifed
in a string list. Either time_shifts is not used or a list with times in secomds. Note that there
has to be one entry fewer than the number of workspaces to add.
@param defType: the file type
@param rawTypes: the raw types
@param lowMem: if the lowMem option should be used
@returns a success message
'''
# Need at least two runs to work
if len(runs) < 1:
Expand All @@ -1451,15 +1463,15 @@ def AddRuns(runs, instrument ='sans2d', saveAsEvent=False, binning = "Monitors",
if time_shifts is None:
time_shifts = []

add_runs(runs = runs,
inst = instrument,
defType = defType,
rawTypes = rawTypes,
lowMem = lowMem,
binning = binning,
saveAsEvent=saveAsEvent,
isOverlay = isOverlay,
time_shifts = time_shifts)
return add_runs(runs = runs,
inst = instrument,
defType = defType,
rawTypes = rawTypes,
lowMem = lowMem,
binning = binning,
saveAsEvent=saveAsEvent,
isOverlay = isOverlay,
time_shifts = time_shifts)



Expand Down

0 comments on commit d7ade86

Please sign in to comment.