From 09f81ff8a007c517eb34cdd5026cc8b35bd3a00d Mon Sep 17 00:00:00 2001
From: "Zhang, Chen" <zhangc@ornl.gov>
Date: Tue, 6 Apr 2021 20:20:50 -0400
Subject: [PATCH] make aware convention

---
 Framework/MDAlgorithms/src/ConvertHFIRSCDtoMDE.cpp           | 5 +++++
 .../PythonInterface/plugins/algorithms/ConvertWANDSCDtoQ.py  | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/Framework/MDAlgorithms/src/ConvertHFIRSCDtoMDE.cpp b/Framework/MDAlgorithms/src/ConvertHFIRSCDtoMDE.cpp
index 2372320deb7..2858f8c9918 100644
--- a/Framework/MDAlgorithms/src/ConvertHFIRSCDtoMDE.cpp
+++ b/Framework/MDAlgorithms/src/ConvertHFIRSCDtoMDE.cpp
@@ -201,6 +201,11 @@ void ConvertHFIRSCDtoMDE::exec() {
   MDEventInserter<MDEventWorkspace<MDEvent<3>, 3>::sptr> inserter(mdws_mdevt_3);
 
   float k = boost::math::float_constants::two_pi / static_cast<float>(wavelength);
+  // check convention to determine the sign of k
+  std::string convention = Kernel::ConfigService::Instance().getString("Q.convention");
+  if (convention == "Crystallography") {
+    k *= -1.f;
+  }
   std::vector<Eigen::Vector3f> q_lab_pre;
   q_lab_pre.reserve(azimuthal.size());
   for (size_t m = 0; m < azimuthal.size(); ++m) {
diff --git a/Framework/PythonInterface/plugins/algorithms/ConvertWANDSCDtoQ.py b/Framework/PythonInterface/plugins/algorithms/ConvertWANDSCDtoQ.py
index 294f316cab1..cc3fc472196 100644
--- a/Framework/PythonInterface/plugins/algorithms/ConvertWANDSCDtoQ.py
+++ b/Framework/PythonInterface/plugins/algorithms/ConvertWANDSCDtoQ.py
@@ -8,6 +8,7 @@ from mantid.api import (PythonAlgorithm, AlgorithmFactory,
                         PropertyMode, WorkspaceProperty, Progress,
                         IMDHistoWorkspaceProperty, mtd)
 from mantid.kernel import Direction, FloatArrayProperty, FloatArrayLengthValidator, StringListValidator, FloatBoundedValidator
+from mantid import config
 from mantid import logger
 import numpy as np
 
@@ -252,6 +253,9 @@ class ConvertWANDSCDtoQ(PythonAlgorithm):
             if inWS.getExperimentInfo(0).getInstrument().getName() == 'HB3A':
                 azim = azim.reshape(512*3, 512).T.flatten()
 
+        # check convention to determine the sign
+        if config['Q.convention'] == 'Crystallography':
+            k *= -1.0
         qlab = np.vstack((np.sin(polar)*np.cos(azim),
                           np.sin(polar)*np.sin(azim),
                           np.cos(polar) - 1)).T * -k # Kf - Ki(0,0,1)
-- 
GitLab