From 3f93ec20172d684cd1e9db46826bc4e92c88d599 Mon Sep 17 00:00:00 2001 From: Artur Glavic Date: Wed, 8 Oct 2025 16:50:17 +0200 Subject: [PATCH] Add Tof projection --- eos/projection.py | 50 ++++++++++++++++++++++++++++++++++++++++++++ eos/reduction_e2h.py | 6 +++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/eos/projection.py b/eos/projection.py index 1ab4efb..b1e5b8e 100644 --- a/eos/projection.py +++ b/eos/projection.py @@ -537,6 +537,56 @@ class TofZProjection(ProjectionInterface): art.remove() plt.draw() +class TofProjection(ProjectionInterface): + tof: np.ndarray + + data: np.recarray + _dtype = np.dtype([ + ('cts', np.float64), + ('I', np.float64), + ('err', np.float64), + ]) + + def __init__(self, tau, foldback=False): + if foldback: + self.tof = np.arange(0, tau, 0.0005) + else: + self.tof = np.arange(0, 2*tau, 0.0005) + self.data = np.zeros(self.tof.shape[0]-1, dtype=self._dtype).view(np.recarray) + self.monitor = 0. + + def project(self, dataset: EventDatasetProtocol, monitor: float): + cts , *_ = np.histogram(dataset.data.events.tof, bins=self.tof) + self.data.cts += cts + self.monitor += monitor + + self.data.I = self.data.cts / self.monitor + self.data.err = np.sqrt(self.data.cts) / self.monitor + + def clear(self): + self.data[:] = 0 + self.monitor = 0. + + def plot(self, **kwargs): + from matplotlib import pyplot as plt + for key in ONLY_MAP: + if key in kwargs: del(kwargs[key]) + + + self._graph = plt.plot(self.tof[:-1]*1e3, self.data.I, **kwargs) + + plt.xlabel('Time of Flight / ms') + plt.ylabel('I / cpm') + plt.xlim(self.tof[0]*1e3, self.tof[-1]*1e3) + plt.title('Time of Flight') + + def update_plot(self): + """ + Inline update of previous plot by just updating the data. + """ + self._graph[0].set_ydata(self.data.I.T) + + class CombinedProjection(ProjectionInterface): """ Allows to put multiple projections together to conveniently generate combined graphs. diff --git a/eos/reduction_e2h.py b/eos/reduction_e2h.py index 6e4f494..5560764 100644 --- a/eos/reduction_e2h.py +++ b/eos/reduction_e2h.py @@ -18,7 +18,8 @@ from .normalization import LZNormalisation from .options import E2HConfig, E2HPlotArguments, IncidentAngle, MonitorType, E2HPlotSelection from . import event_handling as eh from .path_handling import PathResolver -from .projection import CombinedProjection, LZProjection, ProjectionInterface, ReflectivityProjector, TofZProjection, \ +from .projection import CombinedProjection, LZProjection, ProjectionInterface, ReflectivityProjector, TofProjection, \ + TofZProjection, \ YZProjection NEEDS_LAMDA = (E2HPlotSelection.All, E2HPlotSelection.LT, E2HPlotSelection.Q, E2HPlotSelection.L) @@ -147,6 +148,9 @@ class E2HReduction: if self.config.reduction.plot==E2HPlotSelection.TZ: self.projection = TofZProjection(last_file_header.timing.tau, foldback=not self.config.reduction.fast) + if self.config.reduction.plot==E2HPlotSelection.ToF: + self.projection = TofProjection(last_file_header.timing.tau, foldback=not self.config.reduction.fast) + if self.config.reduction.plot==E2HPlotSelection.All: plz = LZProjection(tthh, self.grid) if not self.config.reduction.fast: