From 88ea35b8e3e3804ce822ba9db85fea80c6e4827d Mon Sep 17 00:00:00 2001
From: Philipp Schmidt <philipp.schmidt@xfel.eu>
Date: Wed, 15 Nov 2023 10:05:57 +0100
Subject: [PATCH] Add some more documentation all over the place

---
 .../REMI/REMI_Digitize_and_Transform.ipynb    | 57 +++++++++++++++++--
 1 file changed, 51 insertions(+), 6 deletions(-)

diff --git a/notebooks/REMI/REMI_Digitize_and_Transform.ipynb b/notebooks/REMI/REMI_Digitize_and_Transform.ipynb
index 3ecb0b103..037505b3f 100644
--- a/notebooks/REMI/REMI_Digitize_and_Transform.ipynb
+++ b/notebooks/REMI/REMI_Digitize_and_Transform.ipynb
@@ -165,6 +165,13 @@
     "# Transformation parameters"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "Additional parameters through the user-side configuration file for analog channels and detector settings. Parameters that are deprecated and ignored, but present in the file, are excluded."
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
@@ -360,7 +367,8 @@
     "    ax.legend()\n",
     "    \n",
     "else:\n",
-    "    ppt_data = dc[ppt_source, 'data.bunchPatternTable']"
+    "    ppt_data = dc[ppt_source, 'data.bunchPatternTable']\n",
+    "    print(f'Pulse pattern entries for {(ppt_data.data_counts() > 0).sum()} trains')"
    ]
   },
   {
@@ -423,6 +431,7 @@
     "    \n",
     "    if trailing_trigger:\n",
     "        # Add a single count to every train for trailing trigger.\n",
+    "        warning('Trailing trigger active, all pulse counts are one higher than expected')\n",
     "        pulse_counts += 1\n",
     "\n",
     "    # Compute offsets based on pulse counts.\n",
@@ -456,9 +465,7 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "### Find triggers\n",
-    "\n",
-    "The trigger defines the boundary of a pulse on the digitizer trace, which is stored per train."
+    "### Find triggers"
    ]
   },
   {
@@ -614,6 +621,13 @@
     "pass"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "The trigger defines the boundary of each pulse on the digitizer trace acquired by train. The starting position in samples of each found trigger is shown for the first few trains in detail on the left and all trains on the right."
+   ]
+  },
   {
    "cell_type": "markdown",
    "metadata": {},
@@ -747,6 +761,17 @@
     "    }"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "The analog signal is digitized into discrete edges using a fast timing discriminator. The result of this operation is available in files in the `raw.triggers` dataset.\n",
+    "\n",
+    "The pulse height distribution is an integral view about the chosen digitization thresholds. For more detail, please refer to the spectral pulse height distributions further below.\n",
+    "\n",
+    "The fractional edge distribution visualizes the interpolated component of edge positions, i.e. between discrete digitizer samples. This should in general be flat, in particular a convex shape indicates poor interpolation due to too fast rise times."
+   ]
+  },
   {
    "cell_type": "markdown",
    "metadata": {},
@@ -1021,6 +1046,19 @@
     "pass"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "Overview of initial detector signal correlations before actual hit reconstruction takes place. Only the firsts edge on each channel occuring for each trigger is included, if their times are compatible with a rough time sum window.\n",
+    "\n",
+    "* The top row contains the spectrum of time differences on each wire in temporal coordinates on the left and spatial coordinates on the right (according to configured scale factors).\n",
+    "* The middle row depicts time sums, first integrated and then as a function of time difference. The time sum should generally be somewhat constant, a spectrum-like appearance indicates wire ends have been swapped entirely.\n",
+    "* [HEX-only] The bottom row shows the detector image for each combination of wires based on this limited dataset. There should be no deformations or rotations in any of the wire pairs, else likely channels are misassigned.\n",
+    "\n",
+    "The plot occurs twice if signal-level corrections for time sum or position are enabled."
+   ]
+  },
   {
    "cell_type": "markdown",
    "metadata": {},
@@ -1096,7 +1134,7 @@
     "\n",
     "* `0`: All six anode signals and the corresponding MCP signal were found.\n",
     "* `4`: One signal on layer `u` is missing, all other signals for this event were found.\n",
-    "* `18`: Only one anode signal on each layer was found and the MCP signal is missing. There is no way to check whether this combination of signals is actually valid.\n",
+    "* `18`: Only one anode signal on each layer was found and the MCP signal is missing. There is no way to check whether this combination of signals is actually valid based on the detector data alone.\n",
     "\n",
     "| Method | `u+v+w +mcp` |\n",
     "| - | - |\n",
@@ -1230,16 +1268,23 @@
     "        warning(f'No hits found for {det_name}')\n",
     "        continue\n",
     "    \n",
-    "    im_radius = remi['detector'][det_name]['mcp_radius']*1.1\n",
+    "    mcp_radius = remi['detector'][det_name]['mcp_radius']\n",
+    "    im_radius = mcp_radius * 1.1\n",
     "    \n",
     "    imp.hist2d(flat_hits['x'], flat_hits['y'], bins=(256, 256),\n",
     "               range=[[-im_radius, im_radius], [-im_radius, im_radius]], norm=LogNorm())\n",
+    "    imp.add_patch(Circle(\n",
+    "        (0, 0), mcp_radius,\n",
+    "        linestyle='dashed', edgecolor='red', facecolor='none', linewidth=1))\n",
     "    imp.xaxis.set_label_position('top')\n",
     "    imp.set_xlabel('X / mm')\n",
     "    imp.set_ylabel('Y / mm')\n",
     "    imp.tick_params(right=True, labelright=True, top=True, labeltop=True)\n",
     "    imp.grid()\n",
     "    \n",
+    "    text_pos = 1.05*mcp_radius*np.sin(np.pi/4)\n",
+    "    imp.text(text_pos, text_pos, 'MCP', c='red', ha='left', va='bottom')\n",
+    "    \n",
     "    min_tof = flat_hits['t'].min()\n",
     "    max_tof = flat_hits['t'].max()\n",
     "    \n",
-- 
GitLab