From fd40b75f731be71900afb7502f01ba2af422dbb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20Schulze=20Ei=C3=9Fing?= Date: Wed, 16 Oct 2024 13:14:19 +0200 Subject: [PATCH] Remove WFSim connection (#268) * Remove WFSim connection * Remove test --- fuse/common.py | 19 ---- fuse/plugins/micro_physics/__init__.py | 3 - .../plugins/micro_physics/wfsim_connection.py | 101 ------------------ tests/test_MicroPhysics.py | 5 - 4 files changed, 128 deletions(-) delete mode 100644 fuse/plugins/micro_physics/wfsim_connection.py diff --git a/fuse/common.py b/fuse/common.py index 5f39e8c5..fb54da1f 100644 --- a/fuse/common.py +++ b/fuse/common.py @@ -204,25 +204,6 @@ def ak_num(array, **kwargs): return ak.num(array, **kwargs) -@numba.njit -def offset_range(offsets): - """Computes range of constant event ids while in same offset. E.g. for an - array [1], [1,2,3], [5] this function yields [0, 1, 1, 1, 2]. - - Args: - offsets (ak.array): jagged array offsets. - - Returns: - np.array: Indicies. - """ - res = np.zeros(np.sum(offsets), dtype=np.int32) - i = 0 - for ind, o in enumerate(offsets): - res[i : i + o] = ind - i += o - return res - - # Code shared between S1 and S2 photon propagation def init_spe_scaling_factor_distributions(spe_shapes): # Create a converter array from uniform random numbers to SPE gains diff --git a/fuse/plugins/micro_physics/__init__.py b/fuse/plugins/micro_physics/__init__.py index ada2ed9c..a489ae8a 100644 --- a/fuse/plugins/micro_physics/__init__.py +++ b/fuse/plugins/micro_physics/__init__.py @@ -16,9 +16,6 @@ from . import yields from .yields import * -from . import wfsim_connection -from .wfsim_connection import * - from . import detector_volumes from .detector_volumes import * diff --git a/fuse/plugins/micro_physics/wfsim_connection.py b/fuse/plugins/micro_physics/wfsim_connection.py deleted file mode 100644 index 56cbec6b..00000000 --- a/fuse/plugins/micro_physics/wfsim_connection.py +++ /dev/null @@ -1,101 +0,0 @@ -# This plugin can be used to generate output in a shape that can be read by WFSim -# We can keep this for validation of fuse but it can be removed later on - -import awkward as ak -import numpy as np -import strax - -from ...common import offset_range, reshape_awkward -from ...plugin import FuseBasePlugin - -export, __all__ = strax.exporter() - - -@export -class output_plugin(FuseBasePlugin): - __version__ = "0.2.1" - - depends_on = ("interactions_in_roi", "quanta", "electric_field_values") # Add times later - - provides = "wfsim_instructions" - data_kind = "wfsim_instructions" - - save_when = strax.SaveWhen.TARGET - - dtype = [ - (("Waveform simulator event number", "event_number"), np.int32), - (("Quanta type (S1 photons or S2 electrons)", "type"), np.int8), - (("Time of the interaction [ns]", "time"), np.int64), - (("End Time of the interaction [ns]", "endtime"), np.int64), - (("X position of the cluster [cm]", "x"), np.float32), - (("Y position of the cluster [cm]", "y"), np.float32), - (("Z position of the cluster [cm]", "z"), np.float32), - (("Number of quanta", "amp"), np.int32), - (("Recoil type of interaction", "recoil"), np.int8), - (("Energy deposit of interaction", "e_dep"), np.float32), - (("Eventid like in geant4 output rootfile", "g4id"), np.int32), - (("Volume id giving the detector subvolume", "vol_id"), np.int32), - (("Local field [ V / cm ]", "local_field"), np.float64), - (("Number of excitons", "n_excitons"), np.int32), - (("X position of the primary particle [cm]", "x_pri"), np.float32), - (("Y position of the primary particle [cm]", "y_pri"), np.float32), - (("Z position of the primary particle [cm]", "z_pri"), np.float32), - ] - - def compute(self, interactions_in_roi): - if len(interactions_in_roi) == 0: - return np.zeros(0, dtype=self.dtype) - - instructions = self.awkward_to_wfsim_row_style(interactions_in_roi) - - return instructions - - def awkward_to_wfsim_row_style(self, interactions): - """Converts awkward array instructions into instructions required by WFSim - Args: - interactions: awkward.Array containing GEANT4 simulation information - - Returns: - Structured numpy.array. Each row represents either a S1 or S2 - """ - if len(interactions) == 0: - return np.empty(0, dtype=self.dtype) - - ninteractions = len(interactions["ed"]) - res = np.zeros(2 * ninteractions, dtype=self.dtype) - - # TODO: Currently not supported rows with only electrons or photons due to - # this super odd shape - for i in range(2): - structure = np.unique(interactions["eventid"], return_counts=True)[1] - eventid = reshape_awkward(interactions["eventid"], structure) - - res["event_number"][i::2] = offset_range(ak.to_numpy(ak.num(eventid))) - res["type"][i::2] = i + 1 - res["x"][i::2] = interactions["x"] - res["y"][i::2] = interactions["y"] - res["z"][i::2] = interactions["z"] - res["x_pri"][i::2] = interactions["x_pri"] - res["y_pri"][i::2] = interactions["y_pri"] - res["z_pri"][i::2] = interactions["z_pri"] - res["g4id"][i::2] = interactions["eventid"] - res["vol_id"][i::2] = interactions["vol_id"] - res["e_dep"][i::2] = interactions["ed"] - if "local_field" in res.dtype.names: - res["local_field"][i::2] = interactions["e_field"] - - recoil = interactions["nestid"] - res["recoil"][i::2] = np.where(np.isin(recoil, [0, 6, 7, 8, 11]), recoil, 8) - - if i: - res["amp"][i::2] = interactions["electrons"] - else: - res["amp"][i::2] = interactions["photons"] - if "n_excitons" in res.dtype.names: - res["n_excitons"][i::2] = interactions["excitons"] - - res["time"][i::2] = interactions["time"] - res["endtime"][i::2] = interactions["endtime"] - # Remove entries with no quanta - res = res[res["amp"] > 0] - return res diff --git a/tests/test_MicroPhysics.py b/tests/test_MicroPhysics.py index 2aedb375..43a05382 100644 --- a/tests/test_MicroPhysics.py +++ b/tests/test_MicroPhysics.py @@ -87,11 +87,6 @@ def test_BBFYields(self): self.test_context.register(fuse.plugins.BBFYields) self.test_context.make(self.run_number, "quanta") - @timeout_decorator.timeout(TIMEOUT, exception_message="WFSim connection timed out") - def test_WFSimConnection(self): - self.test_context.register(fuse.plugins.output_plugin) - self.test_context.make(self.run_number, "wfsim_instructions") - @timeout_decorator.timeout(TIMEOUT, exception_message="GasPhasePlugin timed out") def test_GasPhasePlugin(self): self.test_context.register(fuse.plugins.XENONnT_GasPhase)