From ade8249fa6e9d782cc863c2c01bde441275986c4 Mon Sep 17 00:00:00 2001
From: Vickie Lynch <lynchve@ornl.gov>
Date: Tue, 27 Feb 2018 17:17:15 -0500
Subject: [PATCH] Refs #21752 expose azimuthal angle and bank to python

---
 Framework/DataObjects/inc/MantidDataObjects/Peak.h  | 13 +++++++------
 Framework/DataObjects/src/Peak.cpp                  |  9 +++++++++
 Framework/DataObjects/src/PeakColumn.cpp            |  4 +++-
 .../Geometry/inc/MantidGeometry/Crystal/IPeak.h     |  1 +
 .../mantid/api/src/Exports/IPeak.cpp                |  4 ++++
 5 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/Framework/DataObjects/inc/MantidDataObjects/Peak.h b/Framework/DataObjects/inc/MantidDataObjects/Peak.h
index 633cc3927b0..c489bac4a55 100644
--- a/Framework/DataObjects/inc/MantidDataObjects/Peak.h
+++ b/Framework/DataObjects/inc/MantidDataObjects/Peak.h
@@ -111,16 +111,17 @@ public:
   Mantid::Kernel::V3D getDetectorPosition() const override;
   Mantid::Kernel::V3D getDetectorPositionNoCheck() const override;
 
-  void setQSampleFrame(
-      const Mantid::Kernel::V3D &QSampleFrame,
-      boost::optional<double> detectorDistance = boost::none) override;
-  void
-  setQLabFrame(const Mantid::Kernel::V3D &QLabFrame,
-               boost::optional<double> detectorDistance = boost::none) override;
+  void setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame,
+                       boost::optional<double> detectorDistance =
+                           boost::none) override;
+  void setQLabFrame(const Mantid::Kernel::V3D &QLabFrame,
+                    boost::optional<double> detectorDistance =
+                        boost::none) override;
 
   void setWavelength(double wavelength) override;
   double getWavelength() const override;
   double getScattering() const override;
+  double getAzimuthal() const override;
   double getDSpacing() const override;
   double getTOF() const override;
 
diff --git a/Framework/DataObjects/src/Peak.cpp b/Framework/DataObjects/src/Peak.cpp
index c73d1b0ae32..3ea1d8f41fb 100644
--- a/Framework/DataObjects/src/Peak.cpp
+++ b/Framework/DataObjects/src/Peak.cpp
@@ -423,6 +423,15 @@ double Peak::getScattering() const {
   return detDir.angle(beamDir);
 }
 
+// -------------------------------------------------------------------------------------
+/** Calculate the azimuthal angle of the peak  */
+double Peak::getAzimuthal() const {
+  // The detector is at 2 theta scattering angle
+  V3D detDir = detPos - samplePos;
+
+  return atan2(detDir.Y(), detDir.X());
+}
+
 // -------------------------------------------------------------------------------------
 /** Calculate the d-spacing of the peak, in 1/Angstroms  */
 double Peak::getDSpacing() const {
diff --git a/Framework/DataObjects/src/PeakColumn.cpp b/Framework/DataObjects/src/PeakColumn.cpp
index b80c9a8bc5a..5647f46c596 100644
--- a/Framework/DataObjects/src/PeakColumn.cpp
+++ b/Framework/DataObjects/src/PeakColumn.cpp
@@ -194,7 +194,8 @@ void PeakColumn::read(const size_t index, std::istringstream &in) {
   double val;
   try {
     in >> val;
-  } catch (std::exception &e) {
+  }
+  catch (std::exception &e) {
     g_log.error() << "Could not convert input to a number. " << e.what()
                   << '\n';
     return;
@@ -293,6 +294,7 @@ const void *PeakColumn::void_pointer(size_t index) const {
         &value); // Given a pointer it will return a pointer
   } else if (m_name == "RunNumber") {
     value = peak.getRunNumber();
+    return boost::get<int>(&value);
   } else if (m_name == "PeakNumber") {
     value = peak.getPeakNumber();
     return boost::get<int>(&value);
diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/IPeak.h b/Framework/Geometry/inc/MantidGeometry/Crystal/IPeak.h
index edee22eb260..190b05404ef 100644
--- a/Framework/Geometry/inc/MantidGeometry/Crystal/IPeak.h
+++ b/Framework/Geometry/inc/MantidGeometry/Crystal/IPeak.h
@@ -58,6 +58,7 @@ public:
   virtual void setWavelength(double wavelength) = 0;
   virtual double getWavelength() const = 0;
   virtual double getScattering() const = 0;
+  virtual double getAzimuthal() const = 0;
   virtual double getDSpacing() const = 0;
   virtual double getTOF() const = 0;
 
diff --git a/Framework/PythonInterface/mantid/api/src/Exports/IPeak.cpp b/Framework/PythonInterface/mantid/api/src/Exports/IPeak.cpp
index 5d6af3801e8..4f6db0c39c6 100644
--- a/Framework/PythonInterface/mantid/api/src/Exports/IPeak.cpp
+++ b/Framework/PythonInterface/mantid/api/src/Exports/IPeak.cpp
@@ -63,6 +63,8 @@ void export_IPeak() {
            "Return the run number this peak was measured at")
       .def("getPeakNumber", &IPeak::getPeakNumber, arg("self"),
            "Return the peak number for this peak")
+      .def("getBankName", &IPeak::getBankName, arg("self"),
+           "Return the bank name for this peak")
       .def("setRunNumber", &IPeak::setRunNumber,
            (arg("self"), arg("run_number")),
            "Set the run number that measured this peak")
@@ -127,6 +129,8 @@ void export_IPeak() {
            "Return the incident wavelength")
       .def("getScattering", &IPeak::getScattering, arg("self"),
            "Calculate the scattering angle of the peak")
+      .def("getAzimuthal", &IPeak::getAzimuthal, arg("self"),
+           "Calculate the azimuthal angle of the peak")
       .def("getDSpacing", &IPeak::getDSpacing, arg("self"),
            "Calculate the d-spacing of the peak, in 1/Angstroms")
       .def("getTOF", &IPeak::getTOF, arg("self"),
-- 
GitLab