From e6c81c702cdd43ef6742930cd74fb0f8786fc8a0 Mon Sep 17 00:00:00 2001
From: Marina Ganeva <m.ganeva@fz-juelich.de>
Date: Tue, 31 Jul 2018 15:52:14 +0200
Subject: [PATCH] Re #23030 Update documentation

---
 docs/source/algorithms/LoadDNSLegacy-v1.rst | 103 ++++++++++++++++++--
 1 file changed, 97 insertions(+), 6 deletions(-)

diff --git a/docs/source/algorithms/LoadDNSLegacy-v1.rst b/docs/source/algorithms/LoadDNSLegacy-v1.rst
index 3096529d698..656d5947886 100644
--- a/docs/source/algorithms/LoadDNSLegacy-v1.rst
+++ b/docs/source/algorithms/LoadDNSLegacy-v1.rst
@@ -14,13 +14,24 @@ Description
    This algorithm is being developed for a specific instrument. It might get changed or even 
    removed without a notification, should instrument scientists decide to do so.
 
-This algorithm loads a DNS legacy data file into a :ref:`Workspace2D <Workspace2D>`. The loader rotates the detector bank in the position given in the data file.
+This algorithm loads a DNS legacy data file into a :ref:`Workspace2D <Workspace2D>`. The loader rotates the detector bank
+in the position given in the data file.
 
 **Output**
 
 - For diffraction mode data (only one time channel) output is the :ref:`Workspace2D <Workspace2D>` with the X-axis in the wavelength units.
 
-- For TOF data (more than one time channel) output is the :ref:`Workspace2D <Workspace2D>` with the X-axis in TOF units. The lower bin boundary for the channel :math:`i`, :math:`t_i` is calculated as :math:`t_i = t_1 + t_{delay} + i*\Delta t`, where :math:`\Delta t` is the channel width and :math:`t_1` is the time-of-flight from the source (chopper) to sample. Given in the data file channel width is scaled by the *channel_width_factor* which can be set in the :ref:`parameter file <InstrumentParameterFile>`.
+- For TOF data (more than one time channel) output is the :ref:`Workspace2D <Workspace2D>` with the X-axis in TOF units.
+The lower bin boundary for the channel :math:`i`, :math:`t_i` is calculated as :math:`t_i = t_1 + t_{delay} + i*\Delta t`,
+where :math:`\Delta t` is the channel width and :math:`t_1` is the time-of-flight from the source (chopper) to sample.
+Given in the data file channel width is scaled by the *channel_width_factor* which can be set in
+the :ref:`parameter file <InstrumentParameterFile>`.
+
+.. note::
+
+   Since zero time channel is not specified, the algorithm can roll the TOF data to get elastic peak at the right position.
+   For this the **ElasticChannel** - channel number where the elastic peak is observed without correction - should be specified.
+   For comissioning period, the algorithm ignores the elastic channel number given in the data file.
 
 **Normalization**
 
@@ -57,15 +68,15 @@ This algorithm only supports DNS instrument in its configuration with one detect
 Usage
 -----
 
-**Example - Load DNS legacy .d_dat files:**
+**Example 1 - Load DNS diffraction mode .d_dat file:**
 
 .. code-block:: python
 
-   # data file.
-   datafiles = 'dn134011vana.d_dat,dnstof.d_dat'
+   # data file
+   datafile = 'dn134011vana.d_dat'
 
    # Load dataset
-   ws = LoadDNSLegacy(datafiles, Normalization='monitor')
+   ws = LoadDNSLegacy(datafile, Normalization='monitor')
 
    print("This workspace has {} dimensions and has {} histograms.".format(ws.getNumDims(), ws.getNumberHistograms()))
 
@@ -73,6 +84,86 @@ Output:
 
    This workspace has 2 dimensions and has 24 histograms.
 
+
+**Example 2 - Load DNS TOF mode .d_dat file and find the elastic channel:**
+
+.. code-block:: python
+
+   # data file
+   datafile = 'dnstof.d_dat'
+
+   # Load dataset
+   ws = LoadDNSLegacy(datafile, Normalization='no')
+   print("This workspace has {} dimensions and has {} histograms.".format(ws.getNumDims(), ws.getNumberHistograms()))
+
+   # sum spectra over all detectors
+   ws_sum = SumSpectra(ws)
+   # perform fit
+   # Warning: this will work only if elastic peak is stronger than the other peaks!
+   peak_center, sigma = FitGaussian(ws_sum, 0)
+   print("Elastic peak center is at {} microseconds and has sigma={}.".format(round(peak_center), round(sigma)))
+
+   # calculate the elastic channel number
+   channel_width = ws.getRun().getProperty("channel_width").value
+   tof1 = ws.getRun().getProperty("TOF1").value
+   t_delay = ws.getRun().getProperty("delay_time").value
+   epp = round((peak_center - tof1 - t_delay)/channel_width)
+
+   print("The channel width is {} microseconds.".format(channel_width))
+   print("The elastic channel number is: {}.".format(epp))
+
+Output:
+
+   This workspace has 2 dimensions and has 24 histograms.
+   Elastic peak center is at 3023 microseconds and has sigma=62.
+   The channel width is 40.1 microseconds.
+   The elastic channel number is: 65.
+
+
+**Example 3 - Load DNS TOF mode .d_dat file and specify the elastic channel:**
+
+.. code-block:: python
+
+   # data file
+   datafile = 'dnstof.d_dat'
+
+   # Load dataset
+   ws = LoadDNSLegacy(datafile, ElasticChannel=65, Normalization='no')
+
+   # let's check that the elastic peak is at the right position
+   from scipy.constants import m_n, h
+
+   l1 = 0.4     # distance from chopper to sample, m
+   l2 = 0.85   # distance from sample to detector, m
+   wavelength = ws.getRun().getProperty("wavelength").value   # neutron wavelength, Angstrom
+
+   # neutron velocity
+   velocity = h/(m_n*wavelength*1e-10)
+
+   # calculate elastic TOF (total)
+   tof2_elastic = 1e+06*l2/velocity
+   tof1 = ws.getRun().getProperty("TOF1").value
+   t_delay = ws.getRun().getProperty("delay_time").value
+   tof_elastic = t_delay + tof1 + tof2_elastic
+   print ("Calculated elastic TOF: {} microseconds".format(round(tof_elastic)))
+
+   # get elastic TOF from file
+   ws_sum = SumSpectra(ws)
+   peak_center, sigma = FitGaussian(ws_sum, 0)
+   print ("Elastic TOF in the workspace: {} microseconds".format(round(peak_center)))
+
+   # compare difference to the channel width
+   channel_width = ws.getRun().getProperty("channel_width").value
+   print("Difference = {} microseconds < channel width = {} microseconds."
+         .format(round(tof_elastic - peak_center), channel_width, round(sigma)))
+   channel_width = ws.getRun().getProperty("channel_width").value
+
+Output:
+
+   Calculated elastic TOF: 1327 microseconds
+   Elastic TOF in the workspace: 1299 microseconds
+   Difference = 28 microseconds < channel width = 40.1 microseconds.
+
 .. categories::
 
 .. sourcelink::
-- 
GitLab