From de459e8106f12c27243acb6ac8c8cfac08bfe247 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 6 Jul 2026 11:07:39 -0700 Subject: [PATCH 01/60] Load sim props before others `detector` assumes sim.FARFIELD_ENABLED is correct --- larndsim/consts/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larndsim/consts/__init__.py b/larndsim/consts/__init__.py index fe054ae7..c11d4feb 100644 --- a/larndsim/consts/__init__.py +++ b/larndsim/consts/__init__.py @@ -14,6 +14,6 @@ def load_properties(detprop_file, pixel_file, response_file, sim_file): pixel_file (str): pixel layout YAML filename sim_file (str): simulation properties YAML filename """ + sim.set_simulation_properties(sim_file) # must be first! detector.set_detector_properties(detprop_file, pixel_file, response_file) light.set_light_properties(detprop_file) - sim.set_simulation_properties(sim_file) From 65d9f7cf6da035c31edad6f7893d9239d50a1092 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 6 Jul 2026 11:28:54 -0700 Subject: [PATCH 02/60] Add FARFIELD_PROPERTIES --- cli/simulate_pixels.py | 11 +++++++++- larndsim/consts/__init__.py | 9 ++++++-- larndsim/consts/ff_induction.py | 38 ++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index d01f60e5..84a56b56 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -491,6 +491,9 @@ def run_simulation(input_filename, if simulation_properties is None: simulation_properties = cfg['SIM_PROPERTIES'] + + farfield_properties = cfg.get('FARFIELD_PROPERTIES') + if light_simulated is None: try: light_simulated = cfg['LIGHT_SIMULATED'] @@ -636,7 +639,7 @@ def run_simulation(input_filename, light_lut_filename = light_lut_filename[0] RangePush("load_detector_properties") - consts.load_properties(detector_properties, pixel_layout, response_file, simulation_properties) + consts.load_properties(detector_properties, pixel_layout, response_file, simulation_properties, farfield_properties) from larndsim.consts import light, detector, physics, sim RangePop() @@ -667,6 +670,8 @@ def run_simulation(input_filename, else: consts.light.set_light_properties(detector_properties) consts.sim.set_simulation_properties(simulation_properties) + if farfield_properties: + consts.ff_induction.set_ff_induction_properties(farfield_properties) from larndsim.consts import light, physics, sim # set the value for the global variable MOD2MOD_VARIATION @@ -682,6 +687,10 @@ def run_simulation(input_filename, if sim.FARFIELD_ENABLED: print("Far-field mode:", sim.FARFIELD_MODE) + if farfield_properties: + print(f"Far-field properties file: {farfield_properties}") + else: + print("No far-field properties file specified; using default properties") #if light.LIGHT_TRIG_MODE == 1 and not sim.IS_SPILL_SIM: # raise ValueError("The simulation property indicates it is not beam simulation, but the light trigger mode is set to the beam trigger mode!") diff --git a/larndsim/consts/__init__.py b/larndsim/consts/__init__.py index c11d4feb..a226413a 100644 --- a/larndsim/consts/__init__.py +++ b/larndsim/consts/__init__.py @@ -1,9 +1,9 @@ """ Set global variables with detector and physics properties """ -from . import detector, light, sim +from . import detector, light, sim, ff_induction -def load_properties(detprop_file, pixel_file, response_file, sim_file): +def load_properties(detprop_file, pixel_file, response_file, sim_file, farfield_file=None): """ The function loads the detector properties, the pixel geometry, and the simulation YAML files @@ -12,8 +12,13 @@ def load_properties(detprop_file, pixel_file, response_file, sim_file): Args: detprop_file (str): detector properties YAML filename pixel_file (str): pixel layout YAML filename + response_file (str): pixel response filename sim_file (str): simulation properties YAML filename + farfield_file (str, optional): far-field induction properties YAML filename """ sim.set_simulation_properties(sim_file) # must be first! detector.set_detector_properties(detprop_file, pixel_file, response_file) light.set_light_properties(detprop_file) + + if farfield_file: + ff_induction.set_ff_induction_properties(farfield_file) diff --git a/larndsim/consts/ff_induction.py b/larndsim/consts/ff_induction.py index f29e1321..c1413538 100644 --- a/larndsim/consts/ff_induction.py +++ b/larndsim/consts/ff_induction.py @@ -1,4 +1,10 @@ -from .units import cm, microsecond, e +""" +Set far-field induction options +""" + +import yaml + +from .units import cm ################### # Voxel Resolution @@ -38,3 +44,33 @@ # How many terms to include in the dipole expansion DIPOLE_N_TERMS = 5 + + +def set_ff_induction_properties(ffprop_file: str): + """Load far-field induction properties. + + Args: + ffprop_file: YAML filename + """ + global COARSE_VOXEL_SIZE_X + global COARSE_VOXEL_SIZE_Y + global COARSE_VOXEL_SIZE_Z + global CHARGE_COLLECTION_RADIUS + global CHARGE_NEIGHBOR_RADIUS + global INDUCTION_CUTOFF_RADIUS + global FAR_FIELD_SEGMENT_STEP_CM + global INDUCTION_SIGNAL_THRESHOLD + global DIPOLE_N_TERMS + + with open(ffprop_file) as df: + ffprop = yaml.load(df, Loader=yaml.FullLoader) + + COARSE_VOXEL_SIZE_X = ffprop.get('coarse_voxel_size_x', COARSE_VOXEL_SIZE_X) + COARSE_VOXEL_SIZE_Y = ffprop.get('coarse_voxel_size_y', COARSE_VOXEL_SIZE_Y) + COARSE_VOXEL_SIZE_Z = ffprop.get('coarse_voxel_size_z', COARSE_VOXEL_SIZE_Z) + CHARGE_COLLECTION_RADIUS = ffprop.get('charge_collection_radius', CHARGE_COLLECTION_RADIUS) + CHARGE_NEIGHBOR_RADIUS = ffprop.get('charge_neighbor_radius', CHARGE_NEIGHBOR_RADIUS) + INDUCTION_CUTOFF_RADIUS = ffprop.get('induction_cutoff_radius', INDUCTION_CUTOFF_RADIUS) + FAR_FIELD_SEGMENT_STEP_CM = ffprop.get('far_field_segment_step_cm', FAR_FIELD_SEGMENT_STEP_CM) + INDUCTION_SIGNAL_THRESHOLD = ffprop.get('induction_signal_threshold', INDUCTION_SIGNAL_THRESHOLD) + DIPOLE_N_TERMS = ffprop.get('dipole_n_terms', DIPOLE_N_TERMS) From 6ec2cab05e6e82d4c43f99b90d38222443534672 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 6 Jul 2026 11:44:39 -0700 Subject: [PATCH 03/60] Specify directory for farfield_properties --- larndsim/config/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/larndsim/config/config.py b/larndsim/config/config.py index b75c8f20..c8195fbc 100644 --- a/larndsim/config/config.py +++ b/larndsim/config/config.py @@ -13,6 +13,7 @@ SIM_PROPERTIES=f'{MODULE_DIR}/simulation_properties/', PIXEL_LAYOUT=f'{MODULE_DIR}/pixel_layouts/', DET_PROPERTIES=f'{MODULE_DIR}/detector_properties/', + FARFIELD_PROPERTIES=f'{MODULE_DIR}/farfield_properties', RESPONSE=f'{MODULE_DIR}/bin', LIGHT_LUT=f'{MODULE_DIR}/bin', LIGHT_DET_NOISE=f'{MODULE_DIR}/bin', From bc81ddd8ca958a86dcc7ea6ed93514031a89cd5f Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 6 Jul 2026 12:17:00 -0700 Subject: [PATCH 04/60] Make FARFIELD_PROPERTIES optional --- larndsim/config/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larndsim/config/config.py b/larndsim/config/config.py index c8195fbc..590fe3b1 100644 --- a/larndsim/config/config.py +++ b/larndsim/config/config.py @@ -32,7 +32,7 @@ def test_configs(): for cfg_name,cfg_map in CONFIG_MAP.items(): for key in CONFIG_DIR.keys(): - if key == 'PIXEL_THRESHOLDS_FILE' or key == 'PIXEL_PEDESTALS_FILE': + if key in ['PIXEL_THRESHOLDS_FILE','PIXEL_PEDESTALS_FILE', 'FARFIELD_PROPERTIES']: # Don't throw an error for optional keys continue if not key in cfg_map.keys(): From 5d14b61a7516f79c41f17038ec6681d9b902ef3e Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 6 Jul 2026 22:40:25 -0700 Subject: [PATCH 05/60] test: mark charge/neighbor pix as induction-only --- larndsim/far_field/pixel_classifier.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/larndsim/far_field/pixel_classifier.py b/larndsim/far_field/pixel_classifier.py index cfb98632..f4f20407 100644 --- a/larndsim/far_field/pixel_classifier.py +++ b/larndsim/far_field/pixel_classifier.py @@ -236,17 +236,17 @@ def classify_pixels_kernel( thresholds_neighbor = ff_induction.CHARGE_NEIGHBOR_RADIUS * detector.PIXEL_PITCH r_eff_neighbor = thresholds_neighbor + detector.DIFF_N_SIGMAS * sigma_T - # Check charge collection first (highest priority) - if r_trans <= r_eff_cc: - pixel_category = PixelCategory.CHARGE_COLLECTION - break # Can't get higher priority, stop checking - - # Check charge neighbor - if r_trans <= r_eff_neighbor: - # Upgrade if we're currently INACTIVE or INDUCTION_ONLY - if pixel_category < PixelCategory.CHARGE_NEIGHBOR: - pixel_category = PixelCategory.CHARGE_NEIGHBOR - continue + # # Check charge collection first (highest priority) + # if r_trans <= r_eff_cc: + # pixel_category = PixelCategory.CHARGE_COLLECTION + # break # Can't get higher priority, stop checking + + # # Check charge neighbor + # if r_trans <= r_eff_neighbor: + # # Upgrade if we're currently INACTIVE or INDUCTION_ONLY + # if pixel_category < PixelCategory.CHARGE_NEIGHBOR: + # pixel_category = PixelCategory.CHARGE_NEIGHBOR + # continue # Accumulate induction signal (lowest priority) # We accumulate from all segments, then check threshold at the end From 99ba31ee5fa922b1baa726e1b05f64c4c725d142 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 6 Jul 2026 23:10:27 -0700 Subject: [PATCH 06/60] sigh --- larndsim/consts/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/larndsim/consts/__init__.py b/larndsim/consts/__init__.py index a226413a..7af7e72b 100644 --- a/larndsim/consts/__init__.py +++ b/larndsim/consts/__init__.py @@ -17,8 +17,9 @@ def load_properties(detprop_file, pixel_file, response_file, sim_file, farfield_ farfield_file (str, optional): far-field induction properties YAML filename """ sim.set_simulation_properties(sim_file) # must be first! + if farfield_file: + ff_induction.set_ff_induction_properties(farfield_file) + detector.set_detector_properties(detprop_file, pixel_file, response_file) light.set_light_properties(detprop_file) - if farfield_file: - ff_induction.set_ff_induction_properties(farfield_file) From f51ff216b9a92083d4a29f485382f662e1a5b462 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Tue, 7 Jul 2026 10:33:06 -0700 Subject: [PATCH 07/60] Try a fudge factor of 1.5 --- larndsim/far_field/signal_calculation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index ac60623e..a4b63d32 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -280,7 +280,8 @@ def dipole_dWdz(dx: float, dy: float, dz: float, l: float, n_terms: int) -> floa r_m = math.sqrt(r_m_sq) term_sum += (r_m_sq - 3.0*dz_m*dz_m) / (r_m_sq*r_m_sq*r_m) # Total z-component of weighting field gradient (Eq. 3.21) - return term0 + term_sum + fudge = 1.5 + return fudge * (term0 + term_sum) def launch_ffe_kernel( From df67aca83f63cfecc6d705241e8db5f764adda17 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Tue, 7 Jul 2026 21:10:34 -0700 Subject: [PATCH 08/60] don't autoadjust max_radius --- larndsim/consts/detector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/larndsim/consts/detector.py b/larndsim/consts/detector.py index a8af55d6..72a3fd8d 100644 --- a/larndsim/consts/detector.py +++ b/larndsim/consts/detector.py @@ -463,10 +463,10 @@ def set_detector_properties(detprop_file, pixel_file, response_file=None, i_modu MAX_RADIUS = int(detprop['max_radius']) if sim.FARFIELD_ENABLED: - warnings.warn(f'Far-field enabled; setting MAX_RADIUS (currently ' + + warnings.warn(f'Far-field enabled; NOT setting MAX_RADIUS (currently ' + f'{MAX_RADIUS}) to CHARGE_NEIGHBOR_RADIUS ' + f'({ff_induction.CHARGE_NEIGHBOR_RADIUS})') - MAX_RADIUS = ff_induction.CHARGE_NEIGHBOR_RADIUS + # MAX_RADIUS = ff_induction.CHARGE_NEIGHBOR_RADIUS # Prepare neighbouring pixel distance for backtracking # Currently backtracking range is used to convert from segment base to pixel base From 39fcfbe5b32c5c91e4557b2cc3074d31245ce0a1 Mon Sep 17 00:00:00 2001 From: cuddandr Date: Wed, 15 Jul 2026 14:25:32 -0700 Subject: [PATCH 09/60] First pass adding lattice dipole approximation for far-field Quick implementation of a box-aware lattice dipole approximation method to calculate the far field induced current. This method includes dipole images for the walls at X and Y in addition to the Z images across the cathode. The overall method is slightly different from the original infinite-plane method. Each method can be selected via a constant flag in `consts/ff_induction.py`. The lattice dipole has several new constants, the number of X/Y terms and the box half-widths (which should eventually use the geometry info for these numbers). Both methods have a normalization/scale factor, `DIPOLE_SCALE`, defined as a constant to adjust the signal strength. Validated that the code runs, not so much the results yet. --- cli/simulate_pixels.py | 1 + larndsim/consts/ff_induction.py | 15 +- larndsim/consts/sim.py | 3 + larndsim/far_field/signal_calculation.py | 198 ++++++++++++++++++++++- 4 files changed, 212 insertions(+), 5 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index d01f60e5..b17ec652 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -682,6 +682,7 @@ def run_simulation(input_filename, if sim.FARFIELD_ENABLED: print("Far-field mode:", sim.FARFIELD_MODE) + print("Dipole method:", sim.FARFIELD_DIPOLE_MODE) #if light.LIGHT_TRIG_MODE == 1 and not sim.IS_SPILL_SIM: # raise ValueError("The simulation property indicates it is not beam simulation, but the light trigger mode is set to the beam trigger mode!") diff --git a/larndsim/consts/ff_induction.py b/larndsim/consts/ff_induction.py index f29e1321..ff6bafcc 100644 --- a/larndsim/consts/ff_induction.py +++ b/larndsim/consts/ff_induction.py @@ -36,5 +36,18 @@ # Induced Current Normalization #################################### -# How many terms to include in the dipole expansion +# How many terms to include in the z-dipole expansion DIPOLE_N_TERMS = 5 + +# Normalization constant for dipole; found emperically +# ~1.50 for infinite-plane dipole +# ~1.38 for lattice dipole +DIPOLE_SCALE = 1.5 + +# Detector half-width in X/Y for the lattice image calculation +# FIXME: Should use geometry info rather than values specified here +LATTICE_LX = 238.0 +LATTICE_LY = 149.0 + +# Number of X/Y terms to include in the dipole expansion +LATTICE_N_TERMS_XY = 10 diff --git a/larndsim/consts/sim.py b/larndsim/consts/sim.py index f7b6e089..62d1d0ac 100644 --- a/larndsim/consts/sim.py +++ b/larndsim/consts/sim.py @@ -40,6 +40,9 @@ FARFIELD_ENABLED = False FARFIELD_MODE = 'segments' +# Dipole approximation to use: 'infinite_plane' or 'box_lattice' +FARFIELD_DIPOLE_MODE = 'infinite_plane' +# FARFIELD_DIPOLE_MODE = 'box_lattice' def set_simulation_properties(simprop_file): """ diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index ac60623e..cbcd0b90 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -1,5 +1,23 @@ """ Signal calculation module for far field + + consts.sim.FARFIELD_DIPOLE_MODE : str + 'infinite_plane' (default/current behavior, dipole_dWdz -- two + infinite grounded planes, anode + cathode only) or 'box_lattice' + (image_lattice_dWdz -- adds grounded side-wall reflections). + Only affects calculate_ff_segments; calculate_ff_voxels is + unchanged and always uses dipole_dWdz. + + consts.ff_induction.LATTICE_LX, LATTICE_LY : float + Box half-widths for the grounded side walls (x=+/-LATTICE_LX, + y=+/-LATTICE_LY), analogous to BOX_LX/BOX_LY in + hybrid_pixel_response_boxed.py. + + consts.ff_induction.LATTICE_N_TERMS_XY : int + Number of side-wall image reflections per direction (total + (2*LATTICE_N_TERMS_XY+1)**2 lattice points evaluated per + cathode image). ff_induction.DIPOLE_N_TERMS is reused for the + cathode/z-image degree, same as in calculate_ff_segments. """ from functools import lru_cache @@ -235,7 +253,7 @@ def calculate_ff_segments( dy = y - y_pixel dz = z - z_anode - C = detector.RESPONSE_SAMPLING # scale to near-field reponse's time tick + C = ff_induction.DIPOLE_SCALE # scale to near-field reponse's time tick dWdz = C * dipole_dWdz(dx, dy, dz, l, ff_induction.DIPOLE_N_TERMS) total_current += -q_piece * detector.V_DRIFT * dWdz @@ -243,6 +261,119 @@ def calculate_ff_segments( output[p_idx, t_idx] = total_current +@cuda.jit +def calculate_ff_segments_box_lattice( + tracks: cpt.NDArray, + pixel_x: cpt.NDArray[cp.float32], + pixel_y: cpt.NDArray[cp.float32], + z_anode: float, + z_cathode: float, + output: cp.ndarray[tuple[int, int], cp.float32] +): + """ + CUDA kernel: Calculate far-field induced current using segments, + with the box-aware image-lattice far field (image_lattice_dWdz) in + place of the infinite-plane dipole (dipole_dWdz). + + Identical to calculate_ff_segments() in every respect (exclusion + handling, segment splitting, drift geometry) except the per-piece + dW/dz calculation, which additionally reflects images off grounded + side walls at x=+/-ff_induction.LATTICE_LX, y=+/-ff_induction.LATTICE_LY + (see image_lattice_dWdz docstring). Selected via + sim.FARFIELD_DIPOLE_MODE = 'box_lattice' in launch_ffe_kernel(). + + Args: + tracks: structured track array (fields: x_start, y_start, z_start, + x_end, y_end, z_end, n_electrons, pixel_plane, ...) + pixel_x/y: (n_pixels,) array of x/y-positions of each pixel's center + z_anode/cathode: Drift coordinate of the anode/cathode + output: (n_pixels, n_ticks) array of current signals + """ + p_idx, t_idx = cuda.grid(2) + n_pixels = pixel_x.shape[0] + n_ticks = output.shape[1] + if p_idx >= n_pixels or t_idx >= n_ticks: + return + + x_pixel = pixel_x[p_idx] + y_pixel = pixel_y[p_idx] + t = t_idx * detector.TIME_SAMPLING + total_current = 0.0 + + n_segments = tracks.shape[0] + l = abs(z_cathode - z_anode) + exclude_radius = ff_induction.CHARGE_NEIGHBOR_RADIUS * detector.PIXEL_PITCH + + for s_idx in range(n_segments): + segment = tracks[s_idx] + x0 = segment['x_start'] + y0 = segment['y_start'] + z0_seg = segment['z_start'] + x1 = segment['x_end'] + y1 = segment['y_end'] + z1 = segment['z_end'] + + # skip before splitting into sub-pieces. + if exclude_radius > 0.0: + dx0 = abs(x0 - x_pixel) + dy0 = abs(y0 - y_pixel) + dx1 = abs(x1 - x_pixel) + dy1 = abs(y1 - y_pixel) + if max(dx0, dx1) <= exclude_radius and max(dy0, dy1) <= exclude_radius: + continue + + vx = x1 - x0 + vy = y1 - y0 + vz = z1 - z0_seg + seg_len_sq = vx*vx + vy*vy + vz*vz + if seg_len_sq <= 1e-20: + continue + seg_len = math.sqrt(seg_len_sq) + + n_split, step = 1, ff_induction.FAR_FIELD_SEGMENT_STEP_CM + if step > 0.0: + n_split = max(int(math.ceil(seg_len / step)), 1) + + q_piece = segment['n_electrons'] / n_split + + for i_split in range(n_split): + frac = (i_split + 0.5) / n_split + x = x0 + frac * vx + y = y0 + frac * vy + z_start_piece = z0_seg + frac * vz + + # far-field exclusion radius + if exclude_radius > 0.0: + dx_xy = abs(x - x_pixel) + dy_xy = abs(y - y_pixel) + if dx_xy <= exclude_radius or dy_xy <= exclude_radius: + continue + + drift_distance = detector.V_DRIFT * t + if z_start_piece > z_anode: + z = z_start_piece - drift_distance + if z < z_anode: + continue + else: + z = z_start_piece + drift_distance + if z > z_anode: + continue + + dx = x - x_pixel + dy = y - y_pixel + dz = z - z_anode + + C = ff_induction.DIPOLE_SCALE # scale to near-field reponse's time tick + dWdz = C * image_lattice_dWdz( + dx, dy, dz, l, + ff_induction.LATTICE_LX, ff_induction.LATTICE_LY, + ff_induction.DIPOLE_N_TERMS, ff_induction.LATTICE_N_TERMS_XY) + + total_current += -q_piece * detector.V_DRIFT * dWdz + + output[p_idx, t_idx] = total_current + + @nb.njit def dipole_dWdz(dx: float, dy: float, dz: float, l: float, n_terms: int) -> float: """ @@ -283,6 +414,58 @@ def dipole_dWdz(dx: float, dy: float, dz: float, l: float, n_terms: int) -> floa return term0 + term_sum +@nb.njit +def image_lattice_dWdz(dx: float, dy: float, dz: float, l: float, + Lx: float, Ly: float, n_terms_z: int, + n_terms_xy: int) -> float: + """ + Box-aware dipole field calculation: combines a cathode image series + with additional image reflections off grounded side walls at + x=+/-Lx, y=+/-Ly. + + The pixel/dipole sits at the box center (x=y=0 in pixel-relative + coordinates), so reflecting off a wall pair a distance L away + generates images at x = 2*j*L for every integer j, with alternating + sign (-1)**j (j=0 recovers the un-reflected term). Combining + independent reflections off the x- and y-walls gives a 2D lattice + of images with sign (-1)**(j+k), applied to *every* z-image. + + Args: + (dx, dy, dz): Vector from electron to pixel (test point + relative to the dipole), with the pixel taken as the box + center in x, y + l: Drift length (anode-cathode separation) + Lx, Ly: Box half-widths -- grounded walls at x=+/-Lx, y=+/-Ly + n_terms_z: Degree of the cathode image series (images at + dz + 2*n*l for n = -n_terms_z .. n_terms_z) + n_terms_xy: Degree of the side-wall image lattice in each of + x and y (total (2*n_terms_xy+1)**2 lattice points per + z-image) + + Returns: + Calculated Shockley-Ramo weighting field for the current + induced on the pixel, including both cathode and side-wall + image reflections + """ + total = 0.0 + for j in range(-n_terms_xy, n_terms_xy + 1): + dx_j = dx - 2 * j * Lx + for k in range(-n_terms_xy, n_terms_xy + 1): + dy_k = dy - 2 * k * Ly + sign = 1.0 if (j + k) % 2 == 0 else -1.0 + + # Cathode (z) image series, linear 2*n*l spacing (matches + # far_field_image_lattice_potential), reflected off the + # same x/y wall lattice + for n in range(-n_terms_z, n_terms_z + 1): + dz_n = dz + 2 * n * l + r_sq = dx_j*dx_j + dy_k*dy_k + dz_n*dz_n + if r_sq > 1e-20: + r = math.sqrt(r_sq) + total += sign * (r_sq - 3.0*dz_n*dz_n) / (r_sq*r_sq*r) + return total + + def launch_ffe_kernel( tpc_idx: int, tracks: cpt.NDArray, @@ -333,12 +516,12 @@ def launch_voxels(): pixel_x, pixel_y, pixel_categories, z_anode, z_cathode, output) - def launch_segments(): + def launch_segments(kernel): tpc_tracks = tracks[tracks['pixel_plane'] == tpc_idx] if len(tpc_tracks) == 0: return - calculate_ff_segments[BPG, TPB]( + kernel[BPG, TPB]( tpc_tracks, pixel_x, pixel_y, z_anode, z_cathode, output) @@ -347,7 +530,14 @@ def launch_segments(): case 'voxels': launch_voxels() case 'segments': - launch_segments() + match sim.FARFIELD_DIPOLE_MODE: + case 'infinite_plane': + launch_segments(calculate_ff_segments) + case 'box_lattice': + launch_segments(calculate_ff_segments_box_lattice) + case _: + e = f"Invalid farfield_dipole_mode '{sim.FARFIELD_DIPOLE_MODE}'" + raise RuntimeError(e) case _: e = f"Invalid farfield_mode '{sim.FARFIELD_MODE}'" raise RuntimeError(e) From 1e404b54f92ba9e077b867064224dc31cdb73cfc Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 6 Jul 2026 11:07:39 -0700 Subject: [PATCH 10/60] Load sim props before others `detector` assumes sim.FARFIELD_ENABLED is correct --- larndsim/consts/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larndsim/consts/__init__.py b/larndsim/consts/__init__.py index fe054ae7..c11d4feb 100644 --- a/larndsim/consts/__init__.py +++ b/larndsim/consts/__init__.py @@ -14,6 +14,6 @@ def load_properties(detprop_file, pixel_file, response_file, sim_file): pixel_file (str): pixel layout YAML filename sim_file (str): simulation properties YAML filename """ + sim.set_simulation_properties(sim_file) # must be first! detector.set_detector_properties(detprop_file, pixel_file, response_file) light.set_light_properties(detprop_file) - sim.set_simulation_properties(sim_file) From 9d4e095267a7bdc0da17b790b4eb50f9d40f2848 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 6 Jul 2026 11:28:54 -0700 Subject: [PATCH 11/60] Add FARFIELD_PROPERTIES --- cli/simulate_pixels.py | 11 +++++++++- larndsim/consts/__init__.py | 9 ++++++-- larndsim/consts/ff_induction.py | 38 ++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index d01f60e5..84a56b56 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -491,6 +491,9 @@ def run_simulation(input_filename, if simulation_properties is None: simulation_properties = cfg['SIM_PROPERTIES'] + + farfield_properties = cfg.get('FARFIELD_PROPERTIES') + if light_simulated is None: try: light_simulated = cfg['LIGHT_SIMULATED'] @@ -636,7 +639,7 @@ def run_simulation(input_filename, light_lut_filename = light_lut_filename[0] RangePush("load_detector_properties") - consts.load_properties(detector_properties, pixel_layout, response_file, simulation_properties) + consts.load_properties(detector_properties, pixel_layout, response_file, simulation_properties, farfield_properties) from larndsim.consts import light, detector, physics, sim RangePop() @@ -667,6 +670,8 @@ def run_simulation(input_filename, else: consts.light.set_light_properties(detector_properties) consts.sim.set_simulation_properties(simulation_properties) + if farfield_properties: + consts.ff_induction.set_ff_induction_properties(farfield_properties) from larndsim.consts import light, physics, sim # set the value for the global variable MOD2MOD_VARIATION @@ -682,6 +687,10 @@ def run_simulation(input_filename, if sim.FARFIELD_ENABLED: print("Far-field mode:", sim.FARFIELD_MODE) + if farfield_properties: + print(f"Far-field properties file: {farfield_properties}") + else: + print("No far-field properties file specified; using default properties") #if light.LIGHT_TRIG_MODE == 1 and not sim.IS_SPILL_SIM: # raise ValueError("The simulation property indicates it is not beam simulation, but the light trigger mode is set to the beam trigger mode!") diff --git a/larndsim/consts/__init__.py b/larndsim/consts/__init__.py index c11d4feb..a226413a 100644 --- a/larndsim/consts/__init__.py +++ b/larndsim/consts/__init__.py @@ -1,9 +1,9 @@ """ Set global variables with detector and physics properties """ -from . import detector, light, sim +from . import detector, light, sim, ff_induction -def load_properties(detprop_file, pixel_file, response_file, sim_file): +def load_properties(detprop_file, pixel_file, response_file, sim_file, farfield_file=None): """ The function loads the detector properties, the pixel geometry, and the simulation YAML files @@ -12,8 +12,13 @@ def load_properties(detprop_file, pixel_file, response_file, sim_file): Args: detprop_file (str): detector properties YAML filename pixel_file (str): pixel layout YAML filename + response_file (str): pixel response filename sim_file (str): simulation properties YAML filename + farfield_file (str, optional): far-field induction properties YAML filename """ sim.set_simulation_properties(sim_file) # must be first! detector.set_detector_properties(detprop_file, pixel_file, response_file) light.set_light_properties(detprop_file) + + if farfield_file: + ff_induction.set_ff_induction_properties(farfield_file) diff --git a/larndsim/consts/ff_induction.py b/larndsim/consts/ff_induction.py index f29e1321..c1413538 100644 --- a/larndsim/consts/ff_induction.py +++ b/larndsim/consts/ff_induction.py @@ -1,4 +1,10 @@ -from .units import cm, microsecond, e +""" +Set far-field induction options +""" + +import yaml + +from .units import cm ################### # Voxel Resolution @@ -38,3 +44,33 @@ # How many terms to include in the dipole expansion DIPOLE_N_TERMS = 5 + + +def set_ff_induction_properties(ffprop_file: str): + """Load far-field induction properties. + + Args: + ffprop_file: YAML filename + """ + global COARSE_VOXEL_SIZE_X + global COARSE_VOXEL_SIZE_Y + global COARSE_VOXEL_SIZE_Z + global CHARGE_COLLECTION_RADIUS + global CHARGE_NEIGHBOR_RADIUS + global INDUCTION_CUTOFF_RADIUS + global FAR_FIELD_SEGMENT_STEP_CM + global INDUCTION_SIGNAL_THRESHOLD + global DIPOLE_N_TERMS + + with open(ffprop_file) as df: + ffprop = yaml.load(df, Loader=yaml.FullLoader) + + COARSE_VOXEL_SIZE_X = ffprop.get('coarse_voxel_size_x', COARSE_VOXEL_SIZE_X) + COARSE_VOXEL_SIZE_Y = ffprop.get('coarse_voxel_size_y', COARSE_VOXEL_SIZE_Y) + COARSE_VOXEL_SIZE_Z = ffprop.get('coarse_voxel_size_z', COARSE_VOXEL_SIZE_Z) + CHARGE_COLLECTION_RADIUS = ffprop.get('charge_collection_radius', CHARGE_COLLECTION_RADIUS) + CHARGE_NEIGHBOR_RADIUS = ffprop.get('charge_neighbor_radius', CHARGE_NEIGHBOR_RADIUS) + INDUCTION_CUTOFF_RADIUS = ffprop.get('induction_cutoff_radius', INDUCTION_CUTOFF_RADIUS) + FAR_FIELD_SEGMENT_STEP_CM = ffprop.get('far_field_segment_step_cm', FAR_FIELD_SEGMENT_STEP_CM) + INDUCTION_SIGNAL_THRESHOLD = ffprop.get('induction_signal_threshold', INDUCTION_SIGNAL_THRESHOLD) + DIPOLE_N_TERMS = ffprop.get('dipole_n_terms', DIPOLE_N_TERMS) From d77cbb4de20075aaf8f470c09683bd6648004b1f Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 6 Jul 2026 11:44:39 -0700 Subject: [PATCH 12/60] Specify directory for farfield_properties --- larndsim/config/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/larndsim/config/config.py b/larndsim/config/config.py index b75c8f20..c8195fbc 100644 --- a/larndsim/config/config.py +++ b/larndsim/config/config.py @@ -13,6 +13,7 @@ SIM_PROPERTIES=f'{MODULE_DIR}/simulation_properties/', PIXEL_LAYOUT=f'{MODULE_DIR}/pixel_layouts/', DET_PROPERTIES=f'{MODULE_DIR}/detector_properties/', + FARFIELD_PROPERTIES=f'{MODULE_DIR}/farfield_properties', RESPONSE=f'{MODULE_DIR}/bin', LIGHT_LUT=f'{MODULE_DIR}/bin', LIGHT_DET_NOISE=f'{MODULE_DIR}/bin', From 7c91d168b197a8b301b3dd7e74804f3c89033c4b Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 6 Jul 2026 12:17:00 -0700 Subject: [PATCH 13/60] Make FARFIELD_PROPERTIES optional --- larndsim/config/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larndsim/config/config.py b/larndsim/config/config.py index c8195fbc..590fe3b1 100644 --- a/larndsim/config/config.py +++ b/larndsim/config/config.py @@ -32,7 +32,7 @@ def test_configs(): for cfg_name,cfg_map in CONFIG_MAP.items(): for key in CONFIG_DIR.keys(): - if key == 'PIXEL_THRESHOLDS_FILE' or key == 'PIXEL_PEDESTALS_FILE': + if key in ['PIXEL_THRESHOLDS_FILE','PIXEL_PEDESTALS_FILE', 'FARFIELD_PROPERTIES']: # Don't throw an error for optional keys continue if not key in cfg_map.keys(): From c9fcf9a277f663c97161f0684b772d6eff04eb8c Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 6 Jul 2026 23:10:27 -0700 Subject: [PATCH 14/60] sigh --- larndsim/consts/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/larndsim/consts/__init__.py b/larndsim/consts/__init__.py index a226413a..7af7e72b 100644 --- a/larndsim/consts/__init__.py +++ b/larndsim/consts/__init__.py @@ -17,8 +17,9 @@ def load_properties(detprop_file, pixel_file, response_file, sim_file, farfield_ farfield_file (str, optional): far-field induction properties YAML filename """ sim.set_simulation_properties(sim_file) # must be first! + if farfield_file: + ff_induction.set_ff_induction_properties(farfield_file) + detector.set_detector_properties(detprop_file, pixel_file, response_file) light.set_light_properties(detprop_file) - if farfield_file: - ff_induction.set_ff_induction_properties(farfield_file) From fb057cde75a141c6a679908d91fa2ad636693772 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Fri, 17 Jul 2026 07:58:21 -0700 Subject: [PATCH 15/60] Allow dipole mode to be set in simprops yaml --- larndsim/consts/sim.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/larndsim/consts/sim.py b/larndsim/consts/sim.py index 62d1d0ac..1f6794a1 100644 --- a/larndsim/consts/sim.py +++ b/larndsim/consts/sim.py @@ -42,7 +42,6 @@ FARFIELD_MODE = 'segments' # Dipole approximation to use: 'infinite_plane' or 'box_lattice' FARFIELD_DIPOLE_MODE = 'infinite_plane' -# FARFIELD_DIPOLE_MODE = 'box_lattice' def set_simulation_properties(simprop_file): """ @@ -76,6 +75,7 @@ def set_simulation_properties(simprop_file): global FARFIELD_ENABLED global FARFIELD_MODE + global FARFIELD_DIPOLE_MODE with open(simprop_file) as df: simprop = yaml.load(df, Loader=yaml.FullLoader) @@ -105,3 +105,9 @@ def set_simulation_properties(simprop_file): if FARFIELD_MODE not in options: raise RuntimeError(f"Invalid farfield_mode {FARFIELD_MODE}; " + f"must be one of {options}") + + FARFIELD_DIPOLE_MODE = simprop.get('farfield_dipole_mode', FARFIELD_DIPOLE_MODE) + options = ['infinite_plane', 'box_lattice'] + if FARFIELD_DIPOLE_MODE not in options: + raise RuntimeError(f"Invalid farfield_dipole_mode {FARFIELD_DIPOLE_MODE}; " + + f"must be one of {options}") From 1f44b79cb14aeaf718e6bc954851f027994c4713 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Wed, 8 Jul 2026 17:14:19 -0700 Subject: [PATCH 16/60] Revert "don't autoadjust max_radius" This reverts commit df67aca83f63cfecc6d705241e8db5f764adda17. --- larndsim/consts/detector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/larndsim/consts/detector.py b/larndsim/consts/detector.py index 72a3fd8d..a8af55d6 100644 --- a/larndsim/consts/detector.py +++ b/larndsim/consts/detector.py @@ -463,10 +463,10 @@ def set_detector_properties(detprop_file, pixel_file, response_file=None, i_modu MAX_RADIUS = int(detprop['max_radius']) if sim.FARFIELD_ENABLED: - warnings.warn(f'Far-field enabled; NOT setting MAX_RADIUS (currently ' + + warnings.warn(f'Far-field enabled; setting MAX_RADIUS (currently ' + f'{MAX_RADIUS}) to CHARGE_NEIGHBOR_RADIUS ' + f'({ff_induction.CHARGE_NEIGHBOR_RADIUS})') - # MAX_RADIUS = ff_induction.CHARGE_NEIGHBOR_RADIUS + MAX_RADIUS = ff_induction.CHARGE_NEIGHBOR_RADIUS # Prepare neighbouring pixel distance for backtracking # Currently backtracking range is used to convert from segment base to pixel base From c6af4fc26a70bbd434158a44dc3823214f1d07e9 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Wed, 8 Jul 2026 17:08:59 -0700 Subject: [PATCH 17/60] save signals --- cli/simulate_pixels.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 84a56b56..1583d201 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -375,6 +375,17 @@ def do_save_results( compression=compression) +def concat_pad_fast(arrays): + max_cols = max(a.shape[1] for a in arrays) + total_rows = sum(a.shape[0] for a in arrays) + out = np.zeros((total_rows, max_cols), dtype=arrays[0].dtype) + row = 0 + for a in arrays: + out[row:row + a.shape[0], :a.shape[1]] = a + row += a.shape[0] + return out + + def run_simulation(input_filename, output_filename, config='2x2', @@ -1293,6 +1304,7 @@ def digitize_and_update(*args, **kwargs): # Track all pixels processed in near-field batches for this event batch processed_pixels_event = cp.array([], dtype=cp.int32) + saved_pixels_near, saved_mask_ff_plus, saved_signals_near, saved_signals_ff_plus = [], [], [], [] for start_pix, stop_pix in \ tqdm(pixel_ranges, delay=1, desc=' Simulating event %i batches...' % ievd, @@ -1497,6 +1509,11 @@ def digitize_and_update(*args, **kwargs): category=1, voxel_cache=voxel_cache) + saved_pixels_near.append(cp.asnumpy(unique_pix)) + saved_signals_near.append(cp.asnumpy(pixels_signals)) + saved_mask_ff_plus.append(cp.asnumpy(tpc_mask)) + saved_signals_ff_plus.append(cp.asnumpy(ff_signals_tpc)) + pixels_signals[tpc_mask, :] += ff_signals_tpc RangePop() @@ -1588,6 +1605,17 @@ def digitize_and_update(*args, **kwargs): offset_backtrack = cp.zeros(len(induction_pix_ids), dtype=cp.int32) pixels_tracks_signals = cp.zeros(1, dtype=cp.float32) + from pathlib import Path + sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/signals.{ievd:02d}.npz' + sig_path.parent.mkdir(exist_ok=True) + np.savez(sig_path, + pixels_near=np.concatenate(saved_pixels_near), + signals_near=concat_pad_fast(saved_signals_near), + mask_ff_plus=np.concatenate(saved_mask_ff_plus), + signals_ff_plus=concat_pad_fast(saved_signals_ff_plus), + pixels_ff_only=cp.asnumpy(induction_pix_ids), + signals_ff_only=cp.asnumpy(pixels_signals)) + digitize_and_update(unique_eventIDs=unique_eventIDs, unique_pix=induction_pix_ids, pixels_signals=pixels_signals, From f6e6d7df6c8dda11b8e5f0df15791256647ecbe0 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Fri, 17 Jul 2026 14:55:46 -0700 Subject: [PATCH 18/60] dump tracks and pixels --- cli/simulate_pixels.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 1583d201..f29d9a9f 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1500,6 +1500,14 @@ def digitize_and_update(*args, **kwargs): if not np.any(tpc_mask): continue + assert np.all(tpc_mask) # fsdcube + + if ievd == 1 and 3720 in unique_pix: + np.savez(f'ffe_dump.r{ff_induction.CHARGE_NEIGHBOR_RADIUS}.npz', + tracks=all_selected_tracks, pixel_x=pixel_x, pixel_y=pixel_y, + n_ticks=np.array([signals_ticks_t0])) + return + ff_signals_tpc = signal_calculation.launch_ffe_kernel( tpc_idx=tpc_idx, tracks=all_selected_tracks, From 15f4d8db792630ecfeb57bcbfb3c898c7bb8bdad Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Sat, 18 Jul 2026 06:50:43 -0700 Subject: [PATCH 19/60] Revert "dump tracks and pixels" This reverts commit 2cb17721d6ab93427b8bf4f02d812f9b3819a39e. --- cli/simulate_pixels.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index f29d9a9f..1583d201 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1500,14 +1500,6 @@ def digitize_and_update(*args, **kwargs): if not np.any(tpc_mask): continue - assert np.all(tpc_mask) # fsdcube - - if ievd == 1 and 3720 in unique_pix: - np.savez(f'ffe_dump.r{ff_induction.CHARGE_NEIGHBOR_RADIUS}.npz', - tracks=all_selected_tracks, pixel_x=pixel_x, pixel_y=pixel_y, - n_ticks=np.array([signals_ticks_t0])) - return - ff_signals_tpc = signal_calculation.launch_ffe_kernel( tpc_idx=tpc_idx, tracks=all_selected_tracks, From 21969fbdb1b30e418ac00f05be60f360934e6c70 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Sat, 18 Jul 2026 07:19:19 -0700 Subject: [PATCH 20/60] Revert "Try a fudge factor of 1.5" This reverts commit f51ff216b9a92083d4a29f485382f662e1a5b462. --- larndsim/far_field/signal_calculation.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index a4b63d32..ac60623e 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -280,8 +280,7 @@ def dipole_dWdz(dx: float, dy: float, dz: float, l: float, n_terms: int) -> floa r_m = math.sqrt(r_m_sq) term_sum += (r_m_sq - 3.0*dz_m*dz_m) / (r_m_sq*r_m_sq*r_m) # Total z-component of weighting field gradient (Eq. 3.21) - fudge = 1.5 - return fudge * (term0 + term_sum) + return term0 + term_sum def launch_ffe_kernel( From fe78ef4e1f6a8d921928e38a40771527097dd6b4 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Sat, 18 Jul 2026 07:20:59 -0700 Subject: [PATCH 21/60] Fix(?) exclude_radius cut --- larndsim/far_field/signal_calculation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index ac60623e..120f5c4d 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -218,7 +218,7 @@ def calculate_ff_segments( if exclude_radius > 0.0: dx_xy = abs(x - x_pixel) dy_xy = abs(y - y_pixel) - if dx_xy <= exclude_radius or dy_xy <= exclude_radius: + if dx_xy <= exclude_radius and dy_xy <= exclude_radius: continue drift_distance = detector.V_DRIFT * t From a8e5858feb79222ccbf7d3143d8de48a14ed54fb Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 20 Jul 2026 11:23:10 -0700 Subject: [PATCH 22/60] dump tracks and pixels again --- cli/simulate_pixels.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 1583d201..ad651c6d 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1500,6 +1500,15 @@ def digitize_and_update(*args, **kwargs): if not np.any(tpc_mask): continue + assert np.all(tpc_mask) # fsdcube + + ev2save, pix2save = 14, 1145 + if ievd == ev2save and pix2save in unique_pix: + np.savez(f'ffe_dump.r{ff_induction.CHARGE_NEIGHBOR_RADIUS}.{ev2save}.{pix2save}.npz', + tracks=all_selected_tracks, pixel_x=pixel_x, pixel_y=pixel_y, + n_ticks=np.array([signals_ticks_t0])) + return + ff_signals_tpc = signal_calculation.launch_ffe_kernel( tpc_idx=tpc_idx, tracks=all_selected_tracks, From 280908f308105d49bfab018e9538582f1cb86cc2 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 20 Jul 2026 12:53:24 -0700 Subject: [PATCH 23/60] save some more shit --- cli/simulate_pixels.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index ad651c6d..2d75e552 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1506,7 +1506,10 @@ def digitize_and_update(*args, **kwargs): if ievd == ev2save and pix2save in unique_pix: np.savez(f'ffe_dump.r{ff_induction.CHARGE_NEIGHBOR_RADIUS}.{ev2save}.{pix2save}.npz', tracks=all_selected_tracks, pixel_x=pixel_x, pixel_y=pixel_y, - n_ticks=np.array([signals_ticks_t0])) + n_ticks=np.array([signals_ticks_t0]), + pixels_tracks_signals=pixels_tracks_signals, + num_backtrack=num_backtrack, + track_pixel_map=track_pixel_map) return ff_signals_tpc = signal_calculation.launch_ffe_kernel( From a8dc5ac08cf22f0e34d882c0e465e0782f397eb3 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 20 Jul 2026 12:55:37 -0700 Subject: [PATCH 24/60] f --- cli/simulate_pixels.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 2d75e552..b85eedb5 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1510,7 +1510,6 @@ def digitize_and_update(*args, **kwargs): pixels_tracks_signals=pixels_tracks_signals, num_backtrack=num_backtrack, track_pixel_map=track_pixel_map) - return ff_signals_tpc = signal_calculation.launch_ffe_kernel( tpc_idx=tpc_idx, From 7d020c1ff01b4400d34442be7d8b0fca48033aa0 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 20 Jul 2026 14:16:11 -0700 Subject: [PATCH 25/60] Add half-pitch to exclude_radius --- larndsim/far_field/signal_calculation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index 120f5c4d..4690948a 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -174,7 +174,7 @@ def calculate_ff_segments( n_segments = tracks.shape[0] l = abs(z_cathode - z_anode) - exclude_radius = ff_induction.CHARGE_NEIGHBOR_RADIUS * detector.PIXEL_PITCH + exclude_radius = (0.5 + ff_induction.CHARGE_NEIGHBOR_RADIUS) * detector.PIXEL_PITCH for s_idx in range(n_segments): segment = tracks[s_idx] From 61e512f79afb988fd2b855fe8dd27c83c8d3682c Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 20 Jul 2026 15:27:28 -0700 Subject: [PATCH 26/60] Go to 1 mm segment step size --- larndsim/consts/ff_induction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larndsim/consts/ff_induction.py b/larndsim/consts/ff_induction.py index c1413538..dea4b1f7 100644 --- a/larndsim/consts/ff_induction.py +++ b/larndsim/consts/ff_induction.py @@ -33,7 +33,7 @@ INDUCTION_CUTOFF_RADIUS = 50 # cm # Far-field segment split step size (1 mm) -FAR_FIELD_SEGMENT_STEP_CM = 0.5 # cm +FAR_FIELD_SEGMENT_STEP_CM = 0.1 # cm # Minimum induction signal threshold (electrons) INDUCTION_SIGNAL_THRESHOLD = 2000.0 # e- From 8d17b785e72eaf9f14571aad8bcfbd5f36b5a8ce Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Wed, 5 Aug 2026 16:39:07 -0700 Subject: [PATCH 27/60] Change "bt_signals" filename --- cli/simulate_pixels.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index b85eedb5..df59fbd6 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1502,9 +1502,13 @@ def digitize_and_update(*args, **kwargs): assert np.all(tpc_mask) # fsdcube - ev2save, pix2save = 14, 1145 - if ievd == ev2save and pix2save in unique_pix: - np.savez(f'ffe_dump.r{ff_induction.CHARGE_NEIGHBOR_RADIUS}.{ev2save}.{pix2save}.npz', + from pathlib import Path + bt_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/bt_signals.{ievd:02d}.npz' + bt_path.parent.mkdir(exist_ok=True) + # ev2save, pix2save = 14, 1145 + # if ievd == ev2save and pix2save in unique_pix: + if True: + np.savez(bt_path, tracks=all_selected_tracks, pixel_x=pixel_x, pixel_y=pixel_y, n_ticks=np.array([signals_ticks_t0]), pixels_tracks_signals=pixels_tracks_signals, From 274c1799f4f891dc0d947192b7d831e7941b8675 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Wed, 5 Aug 2026 17:21:59 -0700 Subject: [PATCH 28/60] Add separate nf_signals file --- cli/simulate_pixels.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index df59fbd6..6ea60340 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1555,6 +1555,15 @@ def digitize_and_update(*args, **kwargs): results_acc['traj_pixel_map'].append(traj_pixel_map) results_acc['track_pixel_map'].append(track_pixel_map) + from pathlib import Path + sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/nf_signals.{ievd:02d}.npz' + sig_path.parent.mkdir(exist_ok=True) + np.savez(sig_path, + pixels_near=np.concatenate(saved_pixels_near), + signals_near=concat_pad_fast(saved_signals_near), + mask_ff_plus=np.concatenate(saved_mask_ff_plus), + signals_ff_plus=concat_pad_fast(saved_signals_ff_plus)) + # ~~~ Far-field-only induction pixels (not processed above) ~~~ if sim.FARFIELD_ENABLED: RangePush("far_field_induction_only", 2) From 800c5e66764a99814e48ca3cf66ee59abf3266da Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 6 Aug 2026 06:34:08 -0700 Subject: [PATCH 29/60] include i_batch in filenames --- cli/simulate_pixels.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 6ea60340..d5b03b95 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1503,7 +1503,7 @@ def digitize_and_update(*args, **kwargs): assert np.all(tpc_mask) # fsdcube from pathlib import Path - bt_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/bt_signals.{ievd:02d}.npz' + bt_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/bt_signals.{ievd:02d}.{i_batch}.npz' bt_path.parent.mkdir(exist_ok=True) # ev2save, pix2save = 14, 1145 # if ievd == ev2save and pix2save in unique_pix: @@ -1556,7 +1556,7 @@ def digitize_and_update(*args, **kwargs): results_acc['track_pixel_map'].append(track_pixel_map) from pathlib import Path - sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/nf_signals.{ievd:02d}.npz' + sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/nf_signals.{ievd:02d}.{i_batch}.npz' sig_path.parent.mkdir(exist_ok=True) np.savez(sig_path, pixels_near=np.concatenate(saved_pixels_near), @@ -1630,7 +1630,7 @@ def digitize_and_update(*args, **kwargs): pixels_tracks_signals = cp.zeros(1, dtype=cp.float32) from pathlib import Path - sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/signals.{ievd:02d}.npz' + sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/signals.{ievd:02d}.{i_batch}.npz' sig_path.parent.mkdir(exist_ok=True) np.savez(sig_path, pixels_near=np.concatenate(saved_pixels_near), From 63125551fd612b0a86c4fdcdc009f32b8520a33c Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 6 Aug 2026 06:45:15 -0700 Subject: [PATCH 30/60] skip when empty --- cli/simulate_pixels.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index d5b03b95..af53da4f 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1558,11 +1558,12 @@ def digitize_and_update(*args, **kwargs): from pathlib import Path sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/nf_signals.{ievd:02d}.{i_batch}.npz' sig_path.parent.mkdir(exist_ok=True) - np.savez(sig_path, - pixels_near=np.concatenate(saved_pixels_near), - signals_near=concat_pad_fast(saved_signals_near), - mask_ff_plus=np.concatenate(saved_mask_ff_plus), - signals_ff_plus=concat_pad_fast(saved_signals_ff_plus)) + if saved_pixels_near: + np.savez(sig_path, + pixels_near=np.concatenate(saved_pixels_near), + signals_near=concat_pad_fast(saved_signals_near), + mask_ff_plus=np.concatenate(saved_mask_ff_plus), + signals_ff_plus=concat_pad_fast(saved_signals_ff_plus)) # ~~~ Far-field-only induction pixels (not processed above) ~~~ if sim.FARFIELD_ENABLED: @@ -1632,13 +1633,14 @@ def digitize_and_update(*args, **kwargs): from pathlib import Path sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/signals.{ievd:02d}.{i_batch}.npz' sig_path.parent.mkdir(exist_ok=True) - np.savez(sig_path, - pixels_near=np.concatenate(saved_pixels_near), - signals_near=concat_pad_fast(saved_signals_near), - mask_ff_plus=np.concatenate(saved_mask_ff_plus), - signals_ff_plus=concat_pad_fast(saved_signals_ff_plus), - pixels_ff_only=cp.asnumpy(induction_pix_ids), - signals_ff_only=cp.asnumpy(pixels_signals)) + if saved_pixels_near: + np.savez(sig_path, + pixels_near=np.concatenate(saved_pixels_near), + signals_near=concat_pad_fast(saved_signals_near), + mask_ff_plus=np.concatenate(saved_mask_ff_plus), + signals_ff_plus=concat_pad_fast(saved_signals_ff_plus), + pixels_ff_only=cp.asnumpy(induction_pix_ids), + signals_ff_only=cp.asnumpy(pixels_signals)) digitize_and_update(unique_eventIDs=unique_eventIDs, unique_pix=induction_pix_ids, From 645f031e6e6d1d3e77cfa0b5b80f69e845311ba5 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 10 Aug 2026 08:00:10 -0700 Subject: [PATCH 31/60] Add FSD Cube configs for FFE studies --- larndsim/config/config.yaml | 28 +++++++++- .../detector_properties/fsd_cube_prc0.yaml | 56 +++++++++++++++++++ larndsim/farfield_properties/ff_r3.yaml | 1 + larndsim/farfield_properties/ff_r4.yaml | 1 + .../cosmic_sim.ffe_segments.box_lattice.yaml | 14 +++++ ...osmic_sim.ffe_segments.infinite_plane.yaml | 14 +++++ 6 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 larndsim/detector_properties/fsd_cube_prc0.yaml create mode 100644 larndsim/farfield_properties/ff_r3.yaml create mode 100644 larndsim/farfield_properties/ff_r4.yaml create mode 100644 larndsim/simulation_properties/cosmic_sim.ffe_segments.box_lattice.yaml create mode 100644 larndsim/simulation_properties/cosmic_sim.ffe_segments.infinite_plane.yaml diff --git a/larndsim/config/config.yaml b/larndsim/config/config.yaml index 13a85c95..8f7af74d 100644 --- a/larndsim/config/config.yaml +++ b/larndsim/config/config.yaml @@ -123,7 +123,7 @@ fsd_lut_fp16: <<: *fsd LIGHT_LUT: /dvs_ro/cfs/cdirs/dune/www/data/2x2/simulation/larndsim_data/light_LUT/lightLUT_FSD_250123_time_norm_fp16.npz -fsd_cube: +fsd_cube: &fsd_cube SIM_PROPERTIES: cosmic_sim.yaml PIXEL_LAYOUT: multi_tile_layout-3.0.40_fsdcube.yaml DET_PROPERTIES: fsd_cube.yaml @@ -136,3 +136,29 @@ fsd_cube: LIGHT_DET_NOISE: FSD_v01_bin06_larndsim_noise.npy LIGHT_SIMULATED: False MOD2MOD_VARIATION: True + +### TEMPORARY FOR TESTING + +fsd_cube_prc0_r3_plane: + <<: *fsd_cube + DET_PROPERTIES: fsd_cube_prc0.yaml + FARFIELD_PROPERTIES: ff_r3.yaml + SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml + +fsd_cube_prc0_r3_box: + <<: *fsd_cube + DET_PROPERTIES: fsd_cube_prc0.yaml + FARFIELD_PROPERTIES: ff_r3.yaml + SIM_PROPERTIES: cosmic_sim.ffe_segments.box_lattice.yaml + +fsd_cube_prc0_r4_plane: + <<: *fsd_cube + DET_PROPERTIES: fsd_cube_prc0.yaml + FARFIELD_PROPERTIES: ff_r4.yaml + SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml + +fsd_cube_prc0_r4_box: + <<: *fsd_cube + DET_PROPERTIES: fsd_cube_prc0.yaml + FARFIELD_PROPERTIES: ff_r4.yaml + SIM_PROPERTIES: cosmic_sim.ffe_segments.box_lattice.yaml diff --git a/larndsim/detector_properties/fsd_cube_prc0.yaml b/larndsim/detector_properties/fsd_cube_prc0.yaml new file mode 100644 index 00000000..a93312ee --- /dev/null +++ b/larndsim/detector_properties/fsd_cube_prc0.yaml @@ -0,0 +1,56 @@ +temperature: 87.17 # K +e_field: 0.25 # kV/cm ; FSDCube ran at half-nominal e-field +lifetime: 1.1e+3 # us ; based on data-taking conditions +long_diff: 3.78e-6 # cm * cm / us ; calculated by scaling the larnd-sim values by the ratio of 0.5 to 0.25 kV/cm +tran_diff: 6.34e-6 # cm * cm / us ; on the BNL LAr properties page for diffusion, -5% and -28% for D_L and D_T respectively +tpc_offsets: # cm + - [0, 0, 0] +# Note the tile_map convention is different than 2x2 +# as in nd-lar (also in fsd) one vertical row of tiles are connected to one pacman (one io-group) +# while in 2x2 modules, the tile numbering follows horizontal first and then vertical in the 2x4 anode. +tile_map: + - [[1]] +module_to_io_groups: + 1: [1] + +module_to_tpcs: {1: [0]} + +discrimination_threshold: 5.0e3 # e- +v_cm: 0.0 # mV ; FSDCube electronics (LArPix-v3) does not use v_cm +v_ref: 1734.375 # mV ; based on data-taking conditions +v_pedestal: 980 # mV ; based on data-taking conditions +larpix_gain: 3.4e-3 # mV/e- ; based on data-taking conditions +periodic_reset_cycles: 0 # no periodic reset +adc_counts: 1023 # 2**10 - 1; to match LArPix-v3 ADC conversion +adc_scale_factor: 2 # adjust 10-bit to 9-bit counts for LArPix-v3 +adc_hold_delay: 20 # 2us integration window +larpix_version: 3 # LArPix-v3 packets + +# LArPix-v3 has reduced noise, values based on a total input noise measurement of ~350e- +# and on discussion with the LArPix team +reset_noise_charge: 50 # e +uncorrelated_noise_charge: 350 # e +discriminator_noise: 50 # e + +## Light geometry parameters +n_op_channel: 240 + +## Light simulation parameters. +light_trig_mode: 1 + +singlet_fraction: 0.3 +tau_s: 0.001 # us +tau_t: 1.530 # us +enable_lut_smearing: True # sample from the time profile for photon arrival time (True) or use average photon arrival time (False) +op_channel_efficiency: 1 +light_gain: -7.0 +light_tick_size: 0.016 # us +light_det_noise_sample_spacing: 0.016 # us +light_trig_threshold: [-2000, -4500] # [LCM, ACL] +light_trig_mode: 1 +light_window: [0.00, 8.64] # us +light_trig_window: [0.96, 8.64] # us +light_digit_sample_spacing: 0.016 # us +light_nbit: 14 +sipm_response_model: 1 # 0: RLC model; 1: measured +impulse_model: 'larndsim/bin/sipm_impulse.npy' diff --git a/larndsim/farfield_properties/ff_r3.yaml b/larndsim/farfield_properties/ff_r3.yaml new file mode 100644 index 00000000..68bb3c3b --- /dev/null +++ b/larndsim/farfield_properties/ff_r3.yaml @@ -0,0 +1 @@ +charge_neighbor_radius: 3 diff --git a/larndsim/farfield_properties/ff_r4.yaml b/larndsim/farfield_properties/ff_r4.yaml new file mode 100644 index 00000000..7dcc9103 --- /dev/null +++ b/larndsim/farfield_properties/ff_r4.yaml @@ -0,0 +1 @@ +charge_neighbor_radius: 4 diff --git a/larndsim/simulation_properties/cosmic_sim.ffe_segments.box_lattice.yaml b/larndsim/simulation_properties/cosmic_sim.ffe_segments.box_lattice.yaml new file mode 100644 index 00000000..0fea4aa9 --- /dev/null +++ b/larndsim/simulation_properties/cosmic_sim.ffe_segments.box_lattice.yaml @@ -0,0 +1,14 @@ +segment_batch_size: 10000 # track segments +event_batch_size: 2 # tpcs +write_batch_size: 1 # batches +is_spill_sim: 0 # boolean +event_separator: 'event_id' # 'eventID' +tracks_dset_name: 'segments' # or 'segments' +max_events_per_file: 10000 + +max_light_truth_ids: 50 # set to zero to disable light truth backtracking +mc_truth_threshold: 0.1 # pe/us + +farfield_enabled: true +farfield_mode: 'segments' +farfield_dipole_mode: 'box_lattice' diff --git a/larndsim/simulation_properties/cosmic_sim.ffe_segments.infinite_plane.yaml b/larndsim/simulation_properties/cosmic_sim.ffe_segments.infinite_plane.yaml new file mode 100644 index 00000000..b4d6e20e --- /dev/null +++ b/larndsim/simulation_properties/cosmic_sim.ffe_segments.infinite_plane.yaml @@ -0,0 +1,14 @@ +segment_batch_size: 10000 # track segments +event_batch_size: 2 # tpcs +write_batch_size: 1 # batches +is_spill_sim: 0 # boolean +event_separator: 'event_id' # 'eventID' +tracks_dset_name: 'segments' # or 'segments' +max_events_per_file: 10000 + +max_light_truth_ids: 50 # set to zero to disable light truth backtracking +mc_truth_threshold: 0.1 # pe/us + +farfield_enabled: true +farfield_mode: 'segments' +farfield_dipole_mode: 'infinite_plane' From 3707a67068220b3356bca340ac205b0e541fb04a Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Tue, 11 Aug 2026 09:26:52 -0700 Subject: [PATCH 32/60] Fix exclude_radius cut for box-lattice --- larndsim/far_field/signal_calculation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index d8159a60..eebc84a8 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -346,7 +346,7 @@ def calculate_ff_segments_box_lattice( if exclude_radius > 0.0: dx_xy = abs(x - x_pixel) dy_xy = abs(y - y_pixel) - if dx_xy <= exclude_radius or dy_xy <= exclude_radius: + if dx_xy <= exclude_radius and dy_xy <= exclude_radius: continue drift_distance = detector.V_DRIFT * t From ccd7fa897036368ae2325526f7537a82be460eb2 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Tue, 11 Aug 2026 09:45:22 -0700 Subject: [PATCH 33/60] Fix units for LATTICE_LX,LY --- larndsim/consts/ff_induction.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/larndsim/consts/ff_induction.py b/larndsim/consts/ff_induction.py index a9f07564..a49a32d2 100644 --- a/larndsim/consts/ff_induction.py +++ b/larndsim/consts/ff_induction.py @@ -47,9 +47,9 @@ DIPOLE_SCALE = 1.5 # Detector half-width in X/Y for the lattice image calculation -# FIXME: Should use geometry info rather than values specified here -LATTICE_LX = 238.0 -LATTICE_LY = 149.0 +# FIXME: Should use geometry info rather than (FSD Cube) values specified here +LATTICE_LX = 23.80 # cm +LATTICE_LY = 14.90 # cm # Number of X/Y terms to include in the dipole expansion LATTICE_N_TERMS_XY = 10 From 95761a38fc68ece61ae45c24c5b255fce8c846af Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Tue, 11 Aug 2026 10:05:44 -0700 Subject: [PATCH 34/60] Restore scaling of FF signal by RESPONSE_SAMPLING --- larndsim/far_field/signal_calculation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index eebc84a8..dbc74f21 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -253,7 +253,8 @@ def calculate_ff_segments( dy = y - y_pixel dz = z - z_anode - C = ff_induction.DIPOLE_SCALE # scale to near-field reponse's time tick + C = ff_induction.DIPOLE_SCALE + C *= detector.RESPONSE_SAMPLING # scale to near-field reponse's time tick dWdz = C * dipole_dWdz(dx, dy, dz, l, ff_induction.DIPOLE_N_TERMS) total_current += -q_piece * detector.V_DRIFT * dWdz @@ -363,7 +364,8 @@ def calculate_ff_segments_box_lattice( dy = y - y_pixel dz = z - z_anode - C = ff_induction.DIPOLE_SCALE # scale to near-field reponse's time tick + C = ff_induction.DIPOLE_SCALE + C *= detector.RESPONSE_SAMPLING # scale to near-field reponse's time tick dWdz = C * image_lattice_dWdz( dx, dy, dz, l, ff_induction.LATTICE_LX, ff_induction.LATTICE_LY, From 42496bc39c789fb88a8ca8af7d6ba959a0df7dac Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Tue, 11 Aug 2026 20:56:24 -0700 Subject: [PATCH 35/60] Remove signal-saving code --- cli/simulate_pixels.py | 43 ------------------------------------------ 1 file changed, 43 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 909ea996..ad1e78f3 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1312,7 +1312,6 @@ def digitize_and_update(*args, **kwargs): # Track all pixels processed in near-field batches for this event batch processed_pixels_event = cp.array([], dtype=cp.int32) - saved_pixels_near, saved_mask_ff_plus, saved_signals_near, saved_signals_ff_plus = [], [], [], [] for start_pix, stop_pix in \ tqdm(pixel_ranges, delay=1, desc=' Simulating event %i batches...' % ievd, @@ -1510,19 +1509,6 @@ def digitize_and_update(*args, **kwargs): assert np.all(tpc_mask) # fsdcube - from pathlib import Path - bt_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/bt_signals.{ievd:02d}.{i_batch}.npz' - bt_path.parent.mkdir(exist_ok=True) - # ev2save, pix2save = 14, 1145 - # if ievd == ev2save and pix2save in unique_pix: - if True: - np.savez(bt_path, - tracks=all_selected_tracks, pixel_x=pixel_x, pixel_y=pixel_y, - n_ticks=np.array([signals_ticks_t0]), - pixels_tracks_signals=pixels_tracks_signals, - num_backtrack=num_backtrack, - track_pixel_map=track_pixel_map) - ff_signals_tpc = signal_calculation.launch_ffe_kernel( tpc_idx=tpc_idx, tracks=all_selected_tracks, @@ -1532,17 +1518,10 @@ def digitize_and_update(*args, **kwargs): category=1, voxel_cache=voxel_cache) - saved_pixels_near.append(cp.asnumpy(unique_pix)) - saved_signals_near.append(cp.asnumpy(pixels_signals)) - saved_mask_ff_plus.append(cp.asnumpy(tpc_mask)) - saved_signals_ff_plus.append(cp.asnumpy(ff_signals_tpc)) - pixels_signals[tpc_mask, :] += ff_signals_tpc RangePop() - # np.savez(f'sig_{ievd}_{start_pix}_nf.npz', signals=pixels_signals, pixels=unique_pix) - RangePush("get_adc_values", 3) # Here we simulate the electronics response (the self-triggering cycle) and the signal digitization @@ -1563,16 +1542,6 @@ def digitize_and_update(*args, **kwargs): results_acc['traj_pixel_map'].append(traj_pixel_map) results_acc['track_pixel_map'].append(track_pixel_map) - from pathlib import Path - sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/nf_signals.{ievd:02d}.{i_batch}.npz' - sig_path.parent.mkdir(exist_ok=True) - if saved_pixels_near: - np.savez(sig_path, - pixels_near=np.concatenate(saved_pixels_near), - signals_near=concat_pad_fast(saved_signals_near), - mask_ff_plus=np.concatenate(saved_mask_ff_plus), - signals_ff_plus=concat_pad_fast(saved_signals_ff_plus)) - # ~~~ Far-field-only induction pixels (not processed above) ~~~ if sim.FARFIELD_ENABLED: RangePush("far_field_induction_only", 2) @@ -1638,18 +1607,6 @@ def digitize_and_update(*args, **kwargs): offset_backtrack = cp.zeros(len(induction_pix_ids), dtype=cp.int32) pixels_tracks_signals = cp.zeros(1, dtype=cp.float32) - from pathlib import Path - sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/signals.{ievd:02d}.{i_batch}.npz' - sig_path.parent.mkdir(exist_ok=True) - if saved_pixels_near: - np.savez(sig_path, - pixels_near=np.concatenate(saved_pixels_near), - signals_near=concat_pad_fast(saved_signals_near), - mask_ff_plus=np.concatenate(saved_mask_ff_plus), - signals_ff_plus=concat_pad_fast(saved_signals_ff_plus), - pixels_ff_only=cp.asnumpy(induction_pix_ids), - signals_ff_only=cp.asnumpy(pixels_signals)) - digitize_and_update(unique_eventIDs=unique_eventIDs, unique_pix=induction_pix_ids, pixels_signals=pixels_signals, From bee9d14e39a5a0be1d7a6f370d785ed7a5db320a Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Tue, 11 Aug 2026 21:30:56 -0700 Subject: [PATCH 36/60] unit fudge :( --- larndsim/far_field/signal_calculation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index dbc74f21..d3ded5bc 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -254,7 +254,7 @@ def calculate_ff_segments( dz = z - z_anode C = ff_induction.DIPOLE_SCALE - C *= detector.RESPONSE_SAMPLING # scale to near-field reponse's time tick + C *= 0.01 # something something units dWdz = C * dipole_dWdz(dx, dy, dz, l, ff_induction.DIPOLE_N_TERMS) total_current += -q_piece * detector.V_DRIFT * dWdz @@ -365,7 +365,7 @@ def calculate_ff_segments_box_lattice( dz = z - z_anode C = ff_induction.DIPOLE_SCALE - C *= detector.RESPONSE_SAMPLING # scale to near-field reponse's time tick + C *= 0.01 # something something units dWdz = C * image_lattice_dWdz( dx, dy, dz, l, ff_induction.LATTICE_LX, ff_induction.LATTICE_LY, From 3a43eedb38cf5634cc7235ab5d86aed6eeaa8f92 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Sat, 15 Aug 2026 13:38:25 -0700 Subject: [PATCH 37/60] Add Andrew's near_field_dWdz --- larndsim/far_field/signal_calculation.py | 63 ++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index d3ded5bc..6eb4d4ab 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -468,6 +468,69 @@ def image_lattice_dWdz(dx: float, dy: float, dz: float, l: float, return total +@nb.njit +def _corner_angle_dz(a: float, b: float, zpos: float) -> float: + """d/dzpos of _corner_angle(a, b, zpos), holding a, b fixed. + + _corner_angle(a, b, zpos) = arctan2(u, v) with u = a*b (independent + of zpos) and v = zpos*r, r = sqrt(a^2+b^2+zpos^2). Using + d/dt atan2(u, v) = (v u' - u v') / (u^2 + v^2), and u' = 0 here, + this reduces to -u v' / (u^2 + v^2), with + v' = dv/dzpos = r + zpos^2/r = (a^2+b^2+2*zpos^2) / r. + """ + r = math.sqrt(a**2 + b**2 + zpos**2) + u = a * b + v = zpos * r + dv_dzpos = (a**2 + b**2 + 2.0 * zpos**2) / r + return -u * dv_dzpos / (u**2 + v**2) + + +@nb.njit +def _patch_solid_angle_potential_dz(x: float, y: float, z: float, + wx: float, wy: float) -> float: + """d/dzpos of _patch_solid_angle_potential(x, y, zpos, wx, wy), + for zpos > 0 (same convention/singularity guard as that function).""" + x1, x2 = -wx - x, wx - x + y1, y2 = -wy - y, wy - y + domega = (_corner_angle_dz(x2, y2, z) + - _corner_angle_dz(x1, y2, z) + - _corner_angle_dz(x2, y1, z) + + _corner_angle_dz(x1, y1, z)) + return domega / (2.0 * np.pi) + + +@nb.njit +def near_field_dWdz(dx: float, dy: float, dz: float, + wx: float, wy: float, l: float, n_terms: int) \ + -> float: + """Analytic dW/dz of near_field_potential -- the z-component of the + exact finite-size-pixel weighting field, for direct use in place of + finite-differencing near_field_potential. + + Derivation: _patch_signed(x,y,z,wx,wy,z_src) = sign(zz) * g(|zz|) + with zz = z - z_src and g = _patch_solid_angle_potential(x,y,.,wx,wy). + Since d|zz|/dz = sign(zz), the chain rule gives + d/dz [sign(zz) * g(|zz|)] = sign(zz) * g'(|zz|) * sign(zz) + = g'(|zz|) + i.e. the sign(zz) factors cancel and the derivative is just the + *unsigned* zpos-derivative of the solid-angle formula (see + _patch_solid_angle_potential_dz), evaluated at |zz|, for every + image term -- no explicit sign/odd-extension bookkeeping needed + here (verified numerically against central differences of + near_field_potential to ~1e-10 relative error, both within and + across image planes). + + Only the z-component is provided (no dW/dx, dW/dy), matching + dipole_dWdz / image_lattice_dWdz in larndsim_ffe_signal.py, since + the simulated drift is purely along z. + """ + total = 0 + for n in range(-n_terms, n_terms + 1): + total += _patch_solid_angle_potential_dz( + dx, dy, abs(dz - 2 * n * l), wx, wy) + return total + + def launch_ffe_kernel( tpc_idx: int, tracks: cpt.NDArray, From 067367152ee73d7ddf53180fbd821ac35f28719b Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Sat, 15 Aug 2026 13:42:42 -0700 Subject: [PATCH 38/60] tmp switch to near_field_dWdz --- larndsim/far_field/signal_calculation.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index 6eb4d4ab..f5f6afc3 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -253,9 +253,13 @@ def calculate_ff_segments( dy = y - y_pixel dz = z - z_anode - C = ff_induction.DIPOLE_SCALE + # C = ff_induction.DIPOLE_SCALE + C = 1. C *= 0.01 # something something units - dWdz = C * dipole_dWdz(dx, dy, dz, l, ff_induction.DIPOLE_N_TERMS) + # dWdz = C * dipole_dWdz(dx, dy, dz, l, ff_induction.DIPOLE_N_TERMS) + pix_halfw = 0.18 + dWdz = C * near_field_dWdz(dx, dy, dz, pix_halfw, pix_halfw, l, + ff_induction.DIPOLE_N_TERMS) total_current += -q_piece * detector.V_DRIFT * dWdz From 6be367cb8ab5bfbe135bf1ca2f6a4d440198007a Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Sat, 15 Aug 2026 17:40:35 -0700 Subject: [PATCH 39/60] remove "C" factor --- larndsim/far_field/signal_calculation.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index f5f6afc3..aadce659 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -254,12 +254,10 @@ def calculate_ff_segments( dz = z - z_anode # C = ff_induction.DIPOLE_SCALE - C = 1. - C *= 0.01 # something something units # dWdz = C * dipole_dWdz(dx, dy, dz, l, ff_induction.DIPOLE_N_TERMS) pix_halfw = 0.18 - dWdz = C * near_field_dWdz(dx, dy, dz, pix_halfw, pix_halfw, l, - ff_induction.DIPOLE_N_TERMS) + dWdz = near_field_dWdz(dx, dy, dz, pix_halfw, pix_halfw, l, + ff_induction.DIPOLE_N_TERMS) total_current += -q_piece * detector.V_DRIFT * dWdz From eb93187bc0001da3a2bac13b1c8f7548f22da372 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 17 Aug 2026 05:55:02 -0700 Subject: [PATCH 40/60] Revert "Remove signal-saving code" This reverts commit 42496bc39c789fb88a8ca8af7d6ba959a0df7dac. --- cli/simulate_pixels.py | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index ad1e78f3..909ea996 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1312,6 +1312,7 @@ def digitize_and_update(*args, **kwargs): # Track all pixels processed in near-field batches for this event batch processed_pixels_event = cp.array([], dtype=cp.int32) + saved_pixels_near, saved_mask_ff_plus, saved_signals_near, saved_signals_ff_plus = [], [], [], [] for start_pix, stop_pix in \ tqdm(pixel_ranges, delay=1, desc=' Simulating event %i batches...' % ievd, @@ -1509,6 +1510,19 @@ def digitize_and_update(*args, **kwargs): assert np.all(tpc_mask) # fsdcube + from pathlib import Path + bt_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/bt_signals.{ievd:02d}.{i_batch}.npz' + bt_path.parent.mkdir(exist_ok=True) + # ev2save, pix2save = 14, 1145 + # if ievd == ev2save and pix2save in unique_pix: + if True: + np.savez(bt_path, + tracks=all_selected_tracks, pixel_x=pixel_x, pixel_y=pixel_y, + n_ticks=np.array([signals_ticks_t0]), + pixels_tracks_signals=pixels_tracks_signals, + num_backtrack=num_backtrack, + track_pixel_map=track_pixel_map) + ff_signals_tpc = signal_calculation.launch_ffe_kernel( tpc_idx=tpc_idx, tracks=all_selected_tracks, @@ -1518,10 +1532,17 @@ def digitize_and_update(*args, **kwargs): category=1, voxel_cache=voxel_cache) + saved_pixels_near.append(cp.asnumpy(unique_pix)) + saved_signals_near.append(cp.asnumpy(pixels_signals)) + saved_mask_ff_plus.append(cp.asnumpy(tpc_mask)) + saved_signals_ff_plus.append(cp.asnumpy(ff_signals_tpc)) + pixels_signals[tpc_mask, :] += ff_signals_tpc RangePop() + # np.savez(f'sig_{ievd}_{start_pix}_nf.npz', signals=pixels_signals, pixels=unique_pix) + RangePush("get_adc_values", 3) # Here we simulate the electronics response (the self-triggering cycle) and the signal digitization @@ -1542,6 +1563,16 @@ def digitize_and_update(*args, **kwargs): results_acc['traj_pixel_map'].append(traj_pixel_map) results_acc['track_pixel_map'].append(track_pixel_map) + from pathlib import Path + sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/nf_signals.{ievd:02d}.{i_batch}.npz' + sig_path.parent.mkdir(exist_ok=True) + if saved_pixels_near: + np.savez(sig_path, + pixels_near=np.concatenate(saved_pixels_near), + signals_near=concat_pad_fast(saved_signals_near), + mask_ff_plus=np.concatenate(saved_mask_ff_plus), + signals_ff_plus=concat_pad_fast(saved_signals_ff_plus)) + # ~~~ Far-field-only induction pixels (not processed above) ~~~ if sim.FARFIELD_ENABLED: RangePush("far_field_induction_only", 2) @@ -1607,6 +1638,18 @@ def digitize_and_update(*args, **kwargs): offset_backtrack = cp.zeros(len(induction_pix_ids), dtype=cp.int32) pixels_tracks_signals = cp.zeros(1, dtype=cp.float32) + from pathlib import Path + sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/signals.{ievd:02d}.{i_batch}.npz' + sig_path.parent.mkdir(exist_ok=True) + if saved_pixels_near: + np.savez(sig_path, + pixels_near=np.concatenate(saved_pixels_near), + signals_near=concat_pad_fast(saved_signals_near), + mask_ff_plus=np.concatenate(saved_mask_ff_plus), + signals_ff_plus=concat_pad_fast(saved_signals_ff_plus), + pixels_ff_only=cp.asnumpy(induction_pix_ids), + signals_ff_only=cp.asnumpy(pixels_signals)) + digitize_and_update(unique_eventIDs=unique_eventIDs, unique_pix=induction_pix_ids, pixels_signals=pixels_signals, From 117ec2a586038a3236b594d0f741e31096253cb7 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 17 Aug 2026 06:06:06 -0700 Subject: [PATCH 41/60] clean up saved-signals filenames --- cli/simulate_pixels.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 909ea996..2425ebc3 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1313,10 +1313,13 @@ def digitize_and_update(*args, **kwargs): processed_pixels_event = cp.array([], dtype=cp.int32) saved_pixels_near, saved_mask_ff_plus, saved_signals_near, saved_signals_ff_plus = [], [], [], [] + i_pixbatch = -1 for start_pix, stop_pix in \ tqdm(pixel_ranges, delay=1, desc=' Simulating event %i batches...' % ievd, leave=False, ncols=80): + i_pixbatch += 1 + RangePush("setup_pixel_batch") selected_pix = all_unique_pix[start_pix:stop_pix] @@ -1511,17 +1514,14 @@ def digitize_and_update(*args, **kwargs): assert np.all(tpc_mask) # fsdcube from pathlib import Path - bt_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/bt_signals.{ievd:02d}.{i_batch}.npz' + bt_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/bt_signals.{ievd:02d}.{i_pixbatch}.npz' bt_path.parent.mkdir(exist_ok=True) - # ev2save, pix2save = 14, 1145 - # if ievd == ev2save and pix2save in unique_pix: - if True: - np.savez(bt_path, - tracks=all_selected_tracks, pixel_x=pixel_x, pixel_y=pixel_y, - n_ticks=np.array([signals_ticks_t0]), - pixels_tracks_signals=pixels_tracks_signals, - num_backtrack=num_backtrack, - track_pixel_map=track_pixel_map) + np.savez(bt_path, + tracks=all_selected_tracks, pixel_x=pixel_x, pixel_y=pixel_y, + n_ticks=np.array([signals_ticks_t0]), + pixels_tracks_signals=pixels_tracks_signals, + num_backtrack=num_backtrack, + track_pixel_map=track_pixel_map) ff_signals_tpc = signal_calculation.launch_ffe_kernel( tpc_idx=tpc_idx, @@ -1564,7 +1564,7 @@ def digitize_and_update(*args, **kwargs): results_acc['track_pixel_map'].append(track_pixel_map) from pathlib import Path - sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/nf_signals.{ievd:02d}.{i_batch}.npz' + sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/nf_signals.{ievd:02d}.npz' sig_path.parent.mkdir(exist_ok=True) if saved_pixels_near: np.savez(sig_path, @@ -1639,7 +1639,7 @@ def digitize_and_update(*args, **kwargs): pixels_tracks_signals = cp.zeros(1, dtype=cp.float32) from pathlib import Path - sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/signals.{ievd:02d}.{i_batch}.npz' + sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/signals.{ievd:02d}.npz' sig_path.parent.mkdir(exist_ok=True) if saved_pixels_near: np.savez(sig_path, From 80aca50a8fa9e43cf5c8b7dd2e122254df77ec1c Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 17 Aug 2026 16:36:48 -0700 Subject: [PATCH 42/60] WIP: Make sum_pixel_signals add all tracks to sum'd sig Previously, if a track couldn't fit in the backtracking, it wasn't added to the total signal either TODO: Check backtracking weighting/normalization --- larndsim/detsim.py | 55 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/larndsim/detsim.py b/larndsim/detsim.py index 01a23c2f..8497507d 100644 --- a/larndsim/detsim.py +++ b/larndsim/detsim.py @@ -247,38 +247,37 @@ def sum_pixel_signals(pixels_signals, signals, track_t0, pixel_index_map, track_ # size of signals itrk, ipix, itick = cuda.grid(3) + if itrk >= signals.shape[0] or ipix >= signals.shape[1] or itick >= signals.shape[2]: + return - # equivalent to num_backtrack.sum() - total_backtracks = offset_backtrack[-1] + num_backtrack[-1] - - if itrk < signals.shape[0] and ipix < signals.shape[1]: + pixel_index = pixel_index_map[itrk][ipix] + if pixel_index < 0: + return - pixel_index = pixel_index_map[itrk][ipix] - # index into the jagged pixels_tracks_signals array for this pixel and tick - # account track t0 in the backtracking - base_idx = total_backtracks * (itick + track_t0[itrk]) + offset_backtrack[pixel_index] + cuda.atomic.add(pixels_signals, + (pixel_index, itick + track_t0[itrk]), + signals[itrk][ipix][itick]) - if pixel_index >= 0: - counter = -99 - for track_idx in range(track_pixel_map[pixel_index].shape[0]): - if int(track_pixel_map[pixel_index][track_idx]) == -1: - break - if itrk == int(track_pixel_map[pixel_index][track_idx]): - counter = track_idx - if counter >= 0 and itick < signals.shape[2]: - if itick < pixels_signals.shape[1] and itick > -1: - # account track t0 here - cuda.atomic.add(pixels_signals, - (pixel_index, itick + track_t0[itrk]), - signals[itrk][ipix][itick]) - cuda.atomic.add(pixels_tracks_signals, - base_idx + counter, - signals[itrk][ipix][itick]) - break + # equivalent to num_backtrack.sum() + total_backtracks = offset_backtrack[-1] + num_backtrack[-1] - if counter < 0: - # The overflow_flag is for both overflow (too many segments for backtracking) and underflow (no backtracking the pixel is considered too far from the segments) - overflow_flag[pixel_index] = 1 + # index into the jagged pixels_tracks_signals array for this pixel and tick + # account track t0 in the backtracking + base_idx = total_backtracks * (itick + track_t0[itrk]) + offset_backtrack[pixel_index] + + flag = 1 + for track_idx in range(track_pixel_map[pixel_index].shape[0]): + if int(track_pixel_map[pixel_index][track_idx]) == -1: + break + if itrk == int(track_pixel_map[pixel_index][track_idx]): + cuda.atomic.add(pixels_tracks_signals, + base_idx + track_idx, + signals[itrk][ipix][itick]) + flag = 0 + break + + # The overflow_flag is for both overflow (too many segments for backtracking) and underflow (no backtracking the pixel is considered too far from the segments) + overflow_flag[pixel_index] = flag @cuda.jit def get_track_pixel_map(track_pixel_map, unique_pix, pixels): From 466747c166c7de10986c7a71ec616445dba211db Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 17 Aug 2026 17:26:11 -0700 Subject: [PATCH 43/60] rm comment --- cli/simulate_pixels.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 2425ebc3..24b1b571 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1541,8 +1541,6 @@ def digitize_and_update(*args, **kwargs): RangePop() - # np.savez(f'sig_{ievd}_{start_pix}_nf.npz', signals=pixels_signals, pixels=unique_pix) - RangePush("get_adc_values", 3) # Here we simulate the electronics response (the self-triggering cycle) and the signal digitization From db827abcb36943c1bd5cb7e3042215361e177b85 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Mon, 17 Aug 2026 17:26:28 -0700 Subject: [PATCH 44/60] Remove signal-saving code again --- cli/simulate_pixels.py | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 24b1b571..0051a531 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1312,13 +1312,10 @@ def digitize_and_update(*args, **kwargs): # Track all pixels processed in near-field batches for this event batch processed_pixels_event = cp.array([], dtype=cp.int32) - saved_pixels_near, saved_mask_ff_plus, saved_signals_near, saved_signals_ff_plus = [], [], [], [] - i_pixbatch = -1 for start_pix, stop_pix in \ tqdm(pixel_ranges, delay=1, desc=' Simulating event %i batches...' % ievd, leave=False, ncols=80): - i_pixbatch += 1 RangePush("setup_pixel_batch") selected_pix = all_unique_pix[start_pix:stop_pix] @@ -1513,16 +1510,6 @@ def digitize_and_update(*args, **kwargs): assert np.all(tpc_mask) # fsdcube - from pathlib import Path - bt_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/bt_signals.{ievd:02d}.{i_pixbatch}.npz' - bt_path.parent.mkdir(exist_ok=True) - np.savez(bt_path, - tracks=all_selected_tracks, pixel_x=pixel_x, pixel_y=pixel_y, - n_ticks=np.array([signals_ticks_t0]), - pixels_tracks_signals=pixels_tracks_signals, - num_backtrack=num_backtrack, - track_pixel_map=track_pixel_map) - ff_signals_tpc = signal_calculation.launch_ffe_kernel( tpc_idx=tpc_idx, tracks=all_selected_tracks, @@ -1532,11 +1519,6 @@ def digitize_and_update(*args, **kwargs): category=1, voxel_cache=voxel_cache) - saved_pixels_near.append(cp.asnumpy(unique_pix)) - saved_signals_near.append(cp.asnumpy(pixels_signals)) - saved_mask_ff_plus.append(cp.asnumpy(tpc_mask)) - saved_signals_ff_plus.append(cp.asnumpy(ff_signals_tpc)) - pixels_signals[tpc_mask, :] += ff_signals_tpc RangePop() @@ -1561,16 +1543,6 @@ def digitize_and_update(*args, **kwargs): results_acc['traj_pixel_map'].append(traj_pixel_map) results_acc['track_pixel_map'].append(track_pixel_map) - from pathlib import Path - sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/nf_signals.{ievd:02d}.npz' - sig_path.parent.mkdir(exist_ok=True) - if saved_pixels_near: - np.savez(sig_path, - pixels_near=np.concatenate(saved_pixels_near), - signals_near=concat_pad_fast(saved_signals_near), - mask_ff_plus=np.concatenate(saved_mask_ff_plus), - signals_ff_plus=concat_pad_fast(saved_signals_ff_plus)) - # ~~~ Far-field-only induction pixels (not processed above) ~~~ if sim.FARFIELD_ENABLED: RangePush("far_field_induction_only", 2) @@ -1636,18 +1608,6 @@ def digitize_and_update(*args, **kwargs): offset_backtrack = cp.zeros(len(induction_pix_ids), dtype=cp.int32) pixels_tracks_signals = cp.zeros(1, dtype=cp.float32) - from pathlib import Path - sig_path = Path(output_filename).parent / f'{Path(output_filename).name}_signals/signals.{ievd:02d}.npz' - sig_path.parent.mkdir(exist_ok=True) - if saved_pixels_near: - np.savez(sig_path, - pixels_near=np.concatenate(saved_pixels_near), - signals_near=concat_pad_fast(saved_signals_near), - mask_ff_plus=np.concatenate(saved_mask_ff_plus), - signals_ff_plus=concat_pad_fast(saved_signals_ff_plus), - pixels_ff_only=cp.asnumpy(induction_pix_ids), - signals_ff_only=cp.asnumpy(pixels_signals)) - digitize_and_update(unique_eventIDs=unique_eventIDs, unique_pix=induction_pix_ids, pixels_signals=pixels_signals, From e88dfa2384c3027018424096cadc334723f759a9 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Wed, 9 Sep 2026 17:53:29 -0700 Subject: [PATCH 45/60] Add some configs for FFE studies in FSD Cube --- larndsim/config/config.yaml | 24 ++++++++ .../detector_properties/fsd_cube_prc16.yaml | 56 +++++++++++++++++++ .../detector_properties/fsd_cube_prc2.yaml | 56 +++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 larndsim/detector_properties/fsd_cube_prc16.yaml create mode 100644 larndsim/detector_properties/fsd_cube_prc2.yaml diff --git a/larndsim/config/config.yaml b/larndsim/config/config.yaml index 8f7af74d..869dc7a8 100644 --- a/larndsim/config/config.yaml +++ b/larndsim/config/config.yaml @@ -162,3 +162,27 @@ fsd_cube_prc0_r4_box: DET_PROPERTIES: fsd_cube_prc0.yaml FARFIELD_PROPERTIES: ff_r4.yaml SIM_PROPERTIES: cosmic_sim.ffe_segments.box_lattice.yaml + +fsd_cube_prc2_r3_plane: + <<: *fsd_cube + DET_PROPERTIES: fsd_cube_prc2.yaml + FARFIELD_PROPERTIES: ff_r3.yaml + SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml + +fsd_cube_prc2_r4_plane: + <<: *fsd_cube + DET_PROPERTIES: fsd_cube_prc2.yaml + FARFIELD_PROPERTIES: ff_r4.yaml + SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml + +fsd_cube_prc16_r3_plane: + <<: *fsd_cube + DET_PROPERTIES: fsd_cube_prc16.yaml + FARFIELD_PROPERTIES: ff_r3.yaml + SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml + +fsd_cube_prc16_r4_plane: + <<: *fsd_cube + DET_PROPERTIES: fsd_cube_prc16.yaml + FARFIELD_PROPERTIES: ff_r4.yaml + SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml diff --git a/larndsim/detector_properties/fsd_cube_prc16.yaml b/larndsim/detector_properties/fsd_cube_prc16.yaml new file mode 100644 index 00000000..ac309cd3 --- /dev/null +++ b/larndsim/detector_properties/fsd_cube_prc16.yaml @@ -0,0 +1,56 @@ +temperature: 87.17 # K +e_field: 0.25 # kV/cm ; FSDCube ran at half-nominal e-field +lifetime: 1.1e+3 # us ; based on data-taking conditions +long_diff: 3.78e-6 # cm * cm / us ; calculated by scaling the larnd-sim values by the ratio of 0.5 to 0.25 kV/cm +tran_diff: 6.34e-6 # cm * cm / us ; on the BNL LAr properties page for diffusion, -5% and -28% for D_L and D_T respectively +tpc_offsets: # cm + - [0, 0, 0] +# Note the tile_map convention is different than 2x2 +# as in nd-lar (also in fsd) one vertical row of tiles are connected to one pacman (one io-group) +# while in 2x2 modules, the tile numbering follows horizontal first and then vertical in the 2x4 anode. +tile_map: + - [[1]] +module_to_io_groups: + 1: [1] + +module_to_tpcs: {1: [0]} + +discrimination_threshold: 5.0e3 # e- +v_cm: 0.0 # mV ; FSDCube electronics (LArPix-v3) does not use v_cm +v_ref: 1734.375 # mV ; based on data-taking conditions +v_pedestal: 980 # mV ; based on data-taking conditions +larpix_gain: 3.4e-3 # mV/e- ; based on data-taking conditions +periodic_reset_cycles: 1024 +adc_counts: 1023 # 2**10 - 1; to match LArPix-v3 ADC conversion +adc_scale_factor: 2 # adjust 10-bit to 9-bit counts for LArPix-v3 +adc_hold_delay: 20 # 2us integration window +larpix_version: 3 # LArPix-v3 packets + +# LArPix-v3 has reduced noise, values based on a total input noise measurement of ~350e- +# and on discussion with the LArPix team +reset_noise_charge: 50 # e +uncorrelated_noise_charge: 350 # e +discriminator_noise: 50 # e + +## Light geometry parameters +n_op_channel: 240 + +## Light simulation parameters. +light_trig_mode: 1 + +singlet_fraction: 0.3 +tau_s: 0.001 # us +tau_t: 1.530 # us +enable_lut_smearing: True # sample from the time profile for photon arrival time (True) or use average photon arrival time (False) +op_channel_efficiency: 1 +light_gain: -7.0 +light_tick_size: 0.016 # us +light_det_noise_sample_spacing: 0.016 # us +light_trig_threshold: [-2000, -4500] # [LCM, ACL] +light_trig_mode: 1 +light_window: [0.00, 8.64] # us +light_trig_window: [0.96, 8.64] # us +light_digit_sample_spacing: 0.016 # us +light_nbit: 14 +sipm_response_model: 1 # 0: RLC model; 1: measured +impulse_model: 'larndsim/bin/sipm_impulse.npy' diff --git a/larndsim/detector_properties/fsd_cube_prc2.yaml b/larndsim/detector_properties/fsd_cube_prc2.yaml new file mode 100644 index 00000000..616c9ab8 --- /dev/null +++ b/larndsim/detector_properties/fsd_cube_prc2.yaml @@ -0,0 +1,56 @@ +temperature: 87.17 # K +e_field: 0.25 # kV/cm ; FSDCube ran at half-nominal e-field +lifetime: 1.1e+3 # us ; based on data-taking conditions +long_diff: 3.78e-6 # cm * cm / us ; calculated by scaling the larnd-sim values by the ratio of 0.5 to 0.25 kV/cm +tran_diff: 6.34e-6 # cm * cm / us ; on the BNL LAr properties page for diffusion, -5% and -28% for D_L and D_T respectively +tpc_offsets: # cm + - [0, 0, 0] +# Note the tile_map convention is different than 2x2 +# as in nd-lar (also in fsd) one vertical row of tiles are connected to one pacman (one io-group) +# while in 2x2 modules, the tile numbering follows horizontal first and then vertical in the 2x4 anode. +tile_map: + - [[1]] +module_to_io_groups: + 1: [1] + +module_to_tpcs: {1: [0]} + +discrimination_threshold: 5.0e3 # e- +v_cm: 0.0 # mV ; FSDCube electronics (LArPix-v3) does not use v_cm +v_ref: 1734.375 # mV ; based on data-taking conditions +v_pedestal: 980 # mV ; based on data-taking conditions +larpix_gain: 3.4e-3 # mV/e- ; based on data-taking conditions +periodic_reset_cycles: 128 +adc_counts: 1023 # 2**10 - 1; to match LArPix-v3 ADC conversion +adc_scale_factor: 2 # adjust 10-bit to 9-bit counts for LArPix-v3 +adc_hold_delay: 20 # 2us integration window +larpix_version: 3 # LArPix-v3 packets + +# LArPix-v3 has reduced noise, values based on a total input noise measurement of ~350e- +# and on discussion with the LArPix team +reset_noise_charge: 50 # e +uncorrelated_noise_charge: 350 # e +discriminator_noise: 50 # e + +## Light geometry parameters +n_op_channel: 240 + +## Light simulation parameters. +light_trig_mode: 1 + +singlet_fraction: 0.3 +tau_s: 0.001 # us +tau_t: 1.530 # us +enable_lut_smearing: True # sample from the time profile for photon arrival time (True) or use average photon arrival time (False) +op_channel_efficiency: 1 +light_gain: -7.0 +light_tick_size: 0.016 # us +light_det_noise_sample_spacing: 0.016 # us +light_trig_threshold: [-2000, -4500] # [LCM, ACL] +light_trig_mode: 1 +light_window: [0.00, 8.64] # us +light_trig_window: [0.96, 8.64] # us +light_digit_sample_spacing: 0.016 # us +light_nbit: 14 +sipm_response_model: 1 # 0: RLC model; 1: measured +impulse_model: 'larndsim/bin/sipm_impulse.npy' From bb4030c5c186819e41cf4359011b828e71109916 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Wed, 9 Sep 2026 18:00:00 -0700 Subject: [PATCH 46/60] Use 9x9-pixel response for FSD Cube --- larndsim/config/config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/larndsim/config/config.yaml b/larndsim/config/config.yaml index 869dc7a8..cc70ccb7 100644 --- a/larndsim/config/config.yaml +++ b/larndsim/config/config.yaml @@ -127,7 +127,8 @@ fsd_cube: &fsd_cube SIM_PROPERTIES: cosmic_sim.yaml PIXEL_LAYOUT: multi_tile_layout-3.0.40_fsdcube.yaml DET_PROPERTIES: fsd_cube.yaml - RESPONSE: /dvs_ro/cfs/projectdirs/dune/www/data/2x2/simulation/larndsim_data/pixel_response/response_fsdcube_v2d_full_25x25pixel_250Vcm.npz + #RESPONSE: /dvs_ro/cfs/projectdirs/dune/www/data/2x2/simulation/larndsim_data/pixel_response/response_fsdcube_v2d_full_25x25pixel_250Vcm.npz + RESPONSE: /global/cfs/projectdirs/dune/www/data/2x2/simulation/larndsim_data/pixel_response/response_fsdcube_v2d_full_9x9pixel_250Vcm.npz PIXEL_THRESHOLDS_FILE: [thresholds_fsdcube.npz] PIXEL_THRESHOLDS_ID: [0] PIXEL_PEDESTALS_FILE: [pedestals_fsdcube.npz] From 71bc4650850e907eac238bdc473de07d0ee8eef1 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 8 Oct 2026 06:16:33 +0200 Subject: [PATCH 47/60] Remove concat_pad_fast Used only for the signal-saving code (which is buried in a reverted commit): --- cli/simulate_pixels.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 9f297d21..1ef4e938 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -375,17 +375,6 @@ def do_save_results( compression=compression) -def concat_pad_fast(arrays): - max_cols = max(a.shape[1] for a in arrays) - total_rows = sum(a.shape[0] for a in arrays) - out = np.zeros((total_rows, max_cols), dtype=arrays[0].dtype) - row = 0 - for a in arrays: - out[row:row + a.shape[0], :a.shape[1]] = a - row += a.shape[0] - return out - - def run_simulation(input_filename, output_filename, config='2x2', From e0376edb475e1d910d65dd828e2889c2301c9e92 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 8 Oct 2026 06:22:05 +0200 Subject: [PATCH 48/60] Revert "Add some configs for FFE studies in FSD Cube" This reverts commit e88dfa2384c3027018424096cadc334723f759a9. --- larndsim/config/config.yaml | 24 -------- .../detector_properties/fsd_cube_prc16.yaml | 56 ------------------- .../detector_properties/fsd_cube_prc2.yaml | 56 ------------------- 3 files changed, 136 deletions(-) delete mode 100644 larndsim/detector_properties/fsd_cube_prc16.yaml delete mode 100644 larndsim/detector_properties/fsd_cube_prc2.yaml diff --git a/larndsim/config/config.yaml b/larndsim/config/config.yaml index cc70ccb7..20bc0afd 100644 --- a/larndsim/config/config.yaml +++ b/larndsim/config/config.yaml @@ -163,27 +163,3 @@ fsd_cube_prc0_r4_box: DET_PROPERTIES: fsd_cube_prc0.yaml FARFIELD_PROPERTIES: ff_r4.yaml SIM_PROPERTIES: cosmic_sim.ffe_segments.box_lattice.yaml - -fsd_cube_prc2_r3_plane: - <<: *fsd_cube - DET_PROPERTIES: fsd_cube_prc2.yaml - FARFIELD_PROPERTIES: ff_r3.yaml - SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml - -fsd_cube_prc2_r4_plane: - <<: *fsd_cube - DET_PROPERTIES: fsd_cube_prc2.yaml - FARFIELD_PROPERTIES: ff_r4.yaml - SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml - -fsd_cube_prc16_r3_plane: - <<: *fsd_cube - DET_PROPERTIES: fsd_cube_prc16.yaml - FARFIELD_PROPERTIES: ff_r3.yaml - SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml - -fsd_cube_prc16_r4_plane: - <<: *fsd_cube - DET_PROPERTIES: fsd_cube_prc16.yaml - FARFIELD_PROPERTIES: ff_r4.yaml - SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml diff --git a/larndsim/detector_properties/fsd_cube_prc16.yaml b/larndsim/detector_properties/fsd_cube_prc16.yaml deleted file mode 100644 index ac309cd3..00000000 --- a/larndsim/detector_properties/fsd_cube_prc16.yaml +++ /dev/null @@ -1,56 +0,0 @@ -temperature: 87.17 # K -e_field: 0.25 # kV/cm ; FSDCube ran at half-nominal e-field -lifetime: 1.1e+3 # us ; based on data-taking conditions -long_diff: 3.78e-6 # cm * cm / us ; calculated by scaling the larnd-sim values by the ratio of 0.5 to 0.25 kV/cm -tran_diff: 6.34e-6 # cm * cm / us ; on the BNL LAr properties page for diffusion, -5% and -28% for D_L and D_T respectively -tpc_offsets: # cm - - [0, 0, 0] -# Note the tile_map convention is different than 2x2 -# as in nd-lar (also in fsd) one vertical row of tiles are connected to one pacman (one io-group) -# while in 2x2 modules, the tile numbering follows horizontal first and then vertical in the 2x4 anode. -tile_map: - - [[1]] -module_to_io_groups: - 1: [1] - -module_to_tpcs: {1: [0]} - -discrimination_threshold: 5.0e3 # e- -v_cm: 0.0 # mV ; FSDCube electronics (LArPix-v3) does not use v_cm -v_ref: 1734.375 # mV ; based on data-taking conditions -v_pedestal: 980 # mV ; based on data-taking conditions -larpix_gain: 3.4e-3 # mV/e- ; based on data-taking conditions -periodic_reset_cycles: 1024 -adc_counts: 1023 # 2**10 - 1; to match LArPix-v3 ADC conversion -adc_scale_factor: 2 # adjust 10-bit to 9-bit counts for LArPix-v3 -adc_hold_delay: 20 # 2us integration window -larpix_version: 3 # LArPix-v3 packets - -# LArPix-v3 has reduced noise, values based on a total input noise measurement of ~350e- -# and on discussion with the LArPix team -reset_noise_charge: 50 # e -uncorrelated_noise_charge: 350 # e -discriminator_noise: 50 # e - -## Light geometry parameters -n_op_channel: 240 - -## Light simulation parameters. -light_trig_mode: 1 - -singlet_fraction: 0.3 -tau_s: 0.001 # us -tau_t: 1.530 # us -enable_lut_smearing: True # sample from the time profile for photon arrival time (True) or use average photon arrival time (False) -op_channel_efficiency: 1 -light_gain: -7.0 -light_tick_size: 0.016 # us -light_det_noise_sample_spacing: 0.016 # us -light_trig_threshold: [-2000, -4500] # [LCM, ACL] -light_trig_mode: 1 -light_window: [0.00, 8.64] # us -light_trig_window: [0.96, 8.64] # us -light_digit_sample_spacing: 0.016 # us -light_nbit: 14 -sipm_response_model: 1 # 0: RLC model; 1: measured -impulse_model: 'larndsim/bin/sipm_impulse.npy' diff --git a/larndsim/detector_properties/fsd_cube_prc2.yaml b/larndsim/detector_properties/fsd_cube_prc2.yaml deleted file mode 100644 index 616c9ab8..00000000 --- a/larndsim/detector_properties/fsd_cube_prc2.yaml +++ /dev/null @@ -1,56 +0,0 @@ -temperature: 87.17 # K -e_field: 0.25 # kV/cm ; FSDCube ran at half-nominal e-field -lifetime: 1.1e+3 # us ; based on data-taking conditions -long_diff: 3.78e-6 # cm * cm / us ; calculated by scaling the larnd-sim values by the ratio of 0.5 to 0.25 kV/cm -tran_diff: 6.34e-6 # cm * cm / us ; on the BNL LAr properties page for diffusion, -5% and -28% for D_L and D_T respectively -tpc_offsets: # cm - - [0, 0, 0] -# Note the tile_map convention is different than 2x2 -# as in nd-lar (also in fsd) one vertical row of tiles are connected to one pacman (one io-group) -# while in 2x2 modules, the tile numbering follows horizontal first and then vertical in the 2x4 anode. -tile_map: - - [[1]] -module_to_io_groups: - 1: [1] - -module_to_tpcs: {1: [0]} - -discrimination_threshold: 5.0e3 # e- -v_cm: 0.0 # mV ; FSDCube electronics (LArPix-v3) does not use v_cm -v_ref: 1734.375 # mV ; based on data-taking conditions -v_pedestal: 980 # mV ; based on data-taking conditions -larpix_gain: 3.4e-3 # mV/e- ; based on data-taking conditions -periodic_reset_cycles: 128 -adc_counts: 1023 # 2**10 - 1; to match LArPix-v3 ADC conversion -adc_scale_factor: 2 # adjust 10-bit to 9-bit counts for LArPix-v3 -adc_hold_delay: 20 # 2us integration window -larpix_version: 3 # LArPix-v3 packets - -# LArPix-v3 has reduced noise, values based on a total input noise measurement of ~350e- -# and on discussion with the LArPix team -reset_noise_charge: 50 # e -uncorrelated_noise_charge: 350 # e -discriminator_noise: 50 # e - -## Light geometry parameters -n_op_channel: 240 - -## Light simulation parameters. -light_trig_mode: 1 - -singlet_fraction: 0.3 -tau_s: 0.001 # us -tau_t: 1.530 # us -enable_lut_smearing: True # sample from the time profile for photon arrival time (True) or use average photon arrival time (False) -op_channel_efficiency: 1 -light_gain: -7.0 -light_tick_size: 0.016 # us -light_det_noise_sample_spacing: 0.016 # us -light_trig_threshold: [-2000, -4500] # [LCM, ACL] -light_trig_mode: 1 -light_window: [0.00, 8.64] # us -light_trig_window: [0.96, 8.64] # us -light_digit_sample_spacing: 0.016 # us -light_nbit: 14 -sipm_response_model: 1 # 0: RLC model; 1: measured -impulse_model: 'larndsim/bin/sipm_impulse.npy' From d0c5a7b8b5cfde0003bc18e6f7708f957dc5127a Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 8 Oct 2026 06:24:38 +0200 Subject: [PATCH 49/60] Revert "Add FSD Cube configs for FFE studies" This reverts commit 645f031e6e6d1d3e77cfa0b5b80f69e845311ba5. --- larndsim/config/config.yaml | 28 +--------- .../detector_properties/fsd_cube_prc0.yaml | 56 ------------------- larndsim/farfield_properties/ff_r3.yaml | 1 - larndsim/farfield_properties/ff_r4.yaml | 1 - .../cosmic_sim.ffe_segments.box_lattice.yaml | 14 ----- ...osmic_sim.ffe_segments.infinite_plane.yaml | 14 ----- 6 files changed, 1 insertion(+), 113 deletions(-) delete mode 100644 larndsim/detector_properties/fsd_cube_prc0.yaml delete mode 100644 larndsim/farfield_properties/ff_r3.yaml delete mode 100644 larndsim/farfield_properties/ff_r4.yaml delete mode 100644 larndsim/simulation_properties/cosmic_sim.ffe_segments.box_lattice.yaml delete mode 100644 larndsim/simulation_properties/cosmic_sim.ffe_segments.infinite_plane.yaml diff --git a/larndsim/config/config.yaml b/larndsim/config/config.yaml index 20bc0afd..293ebb6c 100644 --- a/larndsim/config/config.yaml +++ b/larndsim/config/config.yaml @@ -123,7 +123,7 @@ fsd_lut_fp16: <<: *fsd LIGHT_LUT: /dvs_ro/cfs/cdirs/dune/www/data/2x2/simulation/larndsim_data/light_LUT/lightLUT_FSD_250123_time_norm_fp16.npz -fsd_cube: &fsd_cube +fsd_cube: SIM_PROPERTIES: cosmic_sim.yaml PIXEL_LAYOUT: multi_tile_layout-3.0.40_fsdcube.yaml DET_PROPERTIES: fsd_cube.yaml @@ -137,29 +137,3 @@ fsd_cube: &fsd_cube LIGHT_DET_NOISE: FSD_v01_bin06_larndsim_noise.npy LIGHT_SIMULATED: False MOD2MOD_VARIATION: True - -### TEMPORARY FOR TESTING - -fsd_cube_prc0_r3_plane: - <<: *fsd_cube - DET_PROPERTIES: fsd_cube_prc0.yaml - FARFIELD_PROPERTIES: ff_r3.yaml - SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml - -fsd_cube_prc0_r3_box: - <<: *fsd_cube - DET_PROPERTIES: fsd_cube_prc0.yaml - FARFIELD_PROPERTIES: ff_r3.yaml - SIM_PROPERTIES: cosmic_sim.ffe_segments.box_lattice.yaml - -fsd_cube_prc0_r4_plane: - <<: *fsd_cube - DET_PROPERTIES: fsd_cube_prc0.yaml - FARFIELD_PROPERTIES: ff_r4.yaml - SIM_PROPERTIES: cosmic_sim.ffe_segments.infinite_plane.yaml - -fsd_cube_prc0_r4_box: - <<: *fsd_cube - DET_PROPERTIES: fsd_cube_prc0.yaml - FARFIELD_PROPERTIES: ff_r4.yaml - SIM_PROPERTIES: cosmic_sim.ffe_segments.box_lattice.yaml diff --git a/larndsim/detector_properties/fsd_cube_prc0.yaml b/larndsim/detector_properties/fsd_cube_prc0.yaml deleted file mode 100644 index a93312ee..00000000 --- a/larndsim/detector_properties/fsd_cube_prc0.yaml +++ /dev/null @@ -1,56 +0,0 @@ -temperature: 87.17 # K -e_field: 0.25 # kV/cm ; FSDCube ran at half-nominal e-field -lifetime: 1.1e+3 # us ; based on data-taking conditions -long_diff: 3.78e-6 # cm * cm / us ; calculated by scaling the larnd-sim values by the ratio of 0.5 to 0.25 kV/cm -tran_diff: 6.34e-6 # cm * cm / us ; on the BNL LAr properties page for diffusion, -5% and -28% for D_L and D_T respectively -tpc_offsets: # cm - - [0, 0, 0] -# Note the tile_map convention is different than 2x2 -# as in nd-lar (also in fsd) one vertical row of tiles are connected to one pacman (one io-group) -# while in 2x2 modules, the tile numbering follows horizontal first and then vertical in the 2x4 anode. -tile_map: - - [[1]] -module_to_io_groups: - 1: [1] - -module_to_tpcs: {1: [0]} - -discrimination_threshold: 5.0e3 # e- -v_cm: 0.0 # mV ; FSDCube electronics (LArPix-v3) does not use v_cm -v_ref: 1734.375 # mV ; based on data-taking conditions -v_pedestal: 980 # mV ; based on data-taking conditions -larpix_gain: 3.4e-3 # mV/e- ; based on data-taking conditions -periodic_reset_cycles: 0 # no periodic reset -adc_counts: 1023 # 2**10 - 1; to match LArPix-v3 ADC conversion -adc_scale_factor: 2 # adjust 10-bit to 9-bit counts for LArPix-v3 -adc_hold_delay: 20 # 2us integration window -larpix_version: 3 # LArPix-v3 packets - -# LArPix-v3 has reduced noise, values based on a total input noise measurement of ~350e- -# and on discussion with the LArPix team -reset_noise_charge: 50 # e -uncorrelated_noise_charge: 350 # e -discriminator_noise: 50 # e - -## Light geometry parameters -n_op_channel: 240 - -## Light simulation parameters. -light_trig_mode: 1 - -singlet_fraction: 0.3 -tau_s: 0.001 # us -tau_t: 1.530 # us -enable_lut_smearing: True # sample from the time profile for photon arrival time (True) or use average photon arrival time (False) -op_channel_efficiency: 1 -light_gain: -7.0 -light_tick_size: 0.016 # us -light_det_noise_sample_spacing: 0.016 # us -light_trig_threshold: [-2000, -4500] # [LCM, ACL] -light_trig_mode: 1 -light_window: [0.00, 8.64] # us -light_trig_window: [0.96, 8.64] # us -light_digit_sample_spacing: 0.016 # us -light_nbit: 14 -sipm_response_model: 1 # 0: RLC model; 1: measured -impulse_model: 'larndsim/bin/sipm_impulse.npy' diff --git a/larndsim/farfield_properties/ff_r3.yaml b/larndsim/farfield_properties/ff_r3.yaml deleted file mode 100644 index 68bb3c3b..00000000 --- a/larndsim/farfield_properties/ff_r3.yaml +++ /dev/null @@ -1 +0,0 @@ -charge_neighbor_radius: 3 diff --git a/larndsim/farfield_properties/ff_r4.yaml b/larndsim/farfield_properties/ff_r4.yaml deleted file mode 100644 index 7dcc9103..00000000 --- a/larndsim/farfield_properties/ff_r4.yaml +++ /dev/null @@ -1 +0,0 @@ -charge_neighbor_radius: 4 diff --git a/larndsim/simulation_properties/cosmic_sim.ffe_segments.box_lattice.yaml b/larndsim/simulation_properties/cosmic_sim.ffe_segments.box_lattice.yaml deleted file mode 100644 index 0fea4aa9..00000000 --- a/larndsim/simulation_properties/cosmic_sim.ffe_segments.box_lattice.yaml +++ /dev/null @@ -1,14 +0,0 @@ -segment_batch_size: 10000 # track segments -event_batch_size: 2 # tpcs -write_batch_size: 1 # batches -is_spill_sim: 0 # boolean -event_separator: 'event_id' # 'eventID' -tracks_dset_name: 'segments' # or 'segments' -max_events_per_file: 10000 - -max_light_truth_ids: 50 # set to zero to disable light truth backtracking -mc_truth_threshold: 0.1 # pe/us - -farfield_enabled: true -farfield_mode: 'segments' -farfield_dipole_mode: 'box_lattice' diff --git a/larndsim/simulation_properties/cosmic_sim.ffe_segments.infinite_plane.yaml b/larndsim/simulation_properties/cosmic_sim.ffe_segments.infinite_plane.yaml deleted file mode 100644 index b4d6e20e..00000000 --- a/larndsim/simulation_properties/cosmic_sim.ffe_segments.infinite_plane.yaml +++ /dev/null @@ -1,14 +0,0 @@ -segment_batch_size: 10000 # track segments -event_batch_size: 2 # tpcs -write_batch_size: 1 # batches -is_spill_sim: 0 # boolean -event_separator: 'event_id' # 'eventID' -tracks_dset_name: 'segments' # or 'segments' -max_events_per_file: 10000 - -max_light_truth_ids: 50 # set to zero to disable light truth backtracking -mc_truth_threshold: 0.1 # pe/us - -farfield_enabled: true -farfield_mode: 'segments' -farfield_dipole_mode: 'infinite_plane' From 551ce8384e4d7b29e28d9c36f8e534bd52846861 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 8 Oct 2026 06:30:30 +0200 Subject: [PATCH 50/60] remove leftover assert --- cli/simulate_pixels.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 1ef4e938..0a2e8907 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -1497,8 +1497,6 @@ def digitize_and_update(*args, **kwargs): if not np.any(tpc_mask): continue - assert np.all(tpc_mask) # fsdcube - ff_signals_tpc = signal_calculation.launch_ffe_kernel( tpc_idx=tpc_idx, tracks=all_selected_tracks, From 0f0b3b6aa511c37fac6318c62032f205004743a4 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 8 Oct 2026 06:44:40 +0200 Subject: [PATCH 51/60] FARFIELD_DIPOLE_MODE -> FARFIELD_SIGNAL_MODEL --- cli/simulate_pixels.py | 2 +- larndsim/consts/sim.py | 14 +++++++------- larndsim/far_field/signal_calculation.py | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 0a2e8907..8218185f 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -697,7 +697,7 @@ def run_simulation(input_filename, else: print("No far-field properties file specified; using default properties") - print("Dipole method:", sim.FARFIELD_DIPOLE_MODE) + print("Dipole method:", sim.FARFIELD_SIGNAL_MODEL) #if light.LIGHT_TRIG_MODE == 1 and not sim.IS_SPILL_SIM: diff --git a/larndsim/consts/sim.py b/larndsim/consts/sim.py index 1f6794a1..0fbf6c7f 100644 --- a/larndsim/consts/sim.py +++ b/larndsim/consts/sim.py @@ -39,9 +39,9 @@ MC_TRUTH_THRESHOLD = 0.1 # pe/us lower is better, but memory usage increases FARFIELD_ENABLED = False -FARFIELD_MODE = 'segments' -# Dipole approximation to use: 'infinite_plane' or 'box_lattice' -FARFIELD_DIPOLE_MODE = 'infinite_plane' +FARFIELD_MODE = 'segments' # 'segments' or 'voxels'; latter unvalidated +# Far-field model to use ('infinite_plane', 'box_lattice') +FARFIELD_SIGNAL_MODEL = 'infinite_plane' def set_simulation_properties(simprop_file): """ @@ -75,7 +75,7 @@ def set_simulation_properties(simprop_file): global FARFIELD_ENABLED global FARFIELD_MODE - global FARFIELD_DIPOLE_MODE + global FARFIELD_SIGNAL_MODEL with open(simprop_file) as df: simprop = yaml.load(df, Loader=yaml.FullLoader) @@ -106,8 +106,8 @@ def set_simulation_properties(simprop_file): raise RuntimeError(f"Invalid farfield_mode {FARFIELD_MODE}; " + f"must be one of {options}") - FARFIELD_DIPOLE_MODE = simprop.get('farfield_dipole_mode', FARFIELD_DIPOLE_MODE) + FARFIELD_SIGNAL_MODEL = simprop.get('farfield_signal_model', FARFIELD_SIGNAL_MODEL) options = ['infinite_plane', 'box_lattice'] - if FARFIELD_DIPOLE_MODE not in options: - raise RuntimeError(f"Invalid farfield_dipole_mode {FARFIELD_DIPOLE_MODE}; " + + if FARFIELD_SIGNAL_MODEL not in options: + raise RuntimeError(f"Invalid farfield_signal_model {FARFIELD_SIGNAL_MODEL}; " + f"must be one of {options}") diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index aadce659..6206aba7 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -1,7 +1,7 @@ """ Signal calculation module for far field - consts.sim.FARFIELD_DIPOLE_MODE : str + consts.sim.FARFIELD_SIGNAL_MODEL : str 'infinite_plane' (default/current behavior, dipole_dWdz -- two infinite grounded planes, anode + cathode only) or 'box_lattice' (image_lattice_dWdz -- adds grounded side-wall reflections). @@ -283,7 +283,7 @@ def calculate_ff_segments_box_lattice( dW/dz calculation, which additionally reflects images off grounded side walls at x=+/-ff_induction.LATTICE_LX, y=+/-ff_induction.LATTICE_LY (see image_lattice_dWdz docstring). Selected via - sim.FARFIELD_DIPOLE_MODE = 'box_lattice' in launch_ffe_kernel(). + sim.FARFIELD_SIGNAL_MODEL = 'box_lattice' in launch_ffe_kernel(). Args: tracks: structured track array (fields: x_start, y_start, z_start, @@ -597,13 +597,13 @@ def launch_segments(kernel): case 'voxels': launch_voxels() case 'segments': - match sim.FARFIELD_DIPOLE_MODE: + match sim.FARFIELD_SIGNAL_MODEL: case 'infinite_plane': launch_segments(calculate_ff_segments) case 'box_lattice': launch_segments(calculate_ff_segments_box_lattice) case _: - e = f"Invalid farfield_dipole_mode '{sim.FARFIELD_DIPOLE_MODE}'" + e = f"Invalid farfield_signal_model '{sim.FARFIELD_SIGNAL_MODEL}'" raise RuntimeError(e) case _: e = f"Invalid farfield_mode '{sim.FARFIELD_MODE}'" From 04ba1e4f50e4a595d39dc2e0ae114d820fd96ff5 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 8 Oct 2026 06:48:51 +0200 Subject: [PATCH 52/60] Hide alternative FFE signal models --- larndsim/consts/ff_induction.py | 16 +- larndsim/consts/sim.py | 3 +- larndsim/far_field/signal_calculation.py | 254 +---------------------- 3 files changed, 3 insertions(+), 270 deletions(-) diff --git a/larndsim/consts/ff_induction.py b/larndsim/consts/ff_induction.py index a49a32d2..6bbadf3d 100644 --- a/larndsim/consts/ff_induction.py +++ b/larndsim/consts/ff_induction.py @@ -41,18 +41,10 @@ # How many terms to include in the z-dipole expansion DIPOLE_N_TERMS = 5 -# Normalization constant for dipole; found emperically +# Normalization constant for dipole; found empirically # ~1.50 for infinite-plane dipole -# ~1.38 for lattice dipole DIPOLE_SCALE = 1.5 -# Detector half-width in X/Y for the lattice image calculation -# FIXME: Should use geometry info rather than (FSD Cube) values specified here -LATTICE_LX = 23.80 # cm -LATTICE_LY = 14.90 # cm - -# Number of X/Y terms to include in the dipole expansion -LATTICE_N_TERMS_XY = 10 def set_ff_induction_properties(ffprop_file: str): """Load far-field induction properties. @@ -70,9 +62,6 @@ def set_ff_induction_properties(ffprop_file: str): global INDUCTION_SIGNAL_THRESHOLD global DIPOLE_N_TERMS global DIPOLE_SCALE - global LATTICE_LX - global LATTICE_LY - global LATTICE_N_TERMS_XY with open(ffprop_file) as df: ffprop = yaml.load(df, Loader=yaml.FullLoader) @@ -87,6 +76,3 @@ def set_ff_induction_properties(ffprop_file: str): INDUCTION_SIGNAL_THRESHOLD = ffprop.get('induction_signal_threshold', INDUCTION_SIGNAL_THRESHOLD) DIPOLE_N_TERMS = ffprop.get('dipole_n_terms', DIPOLE_N_TERMS) DIPOLE_SCALE = ffprop.get('dipole_scale', DIPOLE_SCALE) - LATTICE_LX = ffprop.get('lattice_lx', LATTICE_LX) - LATTICE_LY = ffprop.get('lattice_ly', LATTICE_LY) - LATTICE_N_TERMS_XY = ffprop.get('lattice_n_terms_xy', LATTICE_N_TERMS_XY) diff --git a/larndsim/consts/sim.py b/larndsim/consts/sim.py index 0fbf6c7f..6e5e5cea 100644 --- a/larndsim/consts/sim.py +++ b/larndsim/consts/sim.py @@ -40,7 +40,6 @@ FARFIELD_ENABLED = False FARFIELD_MODE = 'segments' # 'segments' or 'voxels'; latter unvalidated -# Far-field model to use ('infinite_plane', 'box_lattice') FARFIELD_SIGNAL_MODEL = 'infinite_plane' def set_simulation_properties(simprop_file): @@ -107,7 +106,7 @@ def set_simulation_properties(simprop_file): f"must be one of {options}") FARFIELD_SIGNAL_MODEL = simprop.get('farfield_signal_model', FARFIELD_SIGNAL_MODEL) - options = ['infinite_plane', 'box_lattice'] + options = ['infinite_plane'] if FARFIELD_SIGNAL_MODEL not in options: raise RuntimeError(f"Invalid farfield_signal_model {FARFIELD_SIGNAL_MODEL}; " + f"must be one of {options}") diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index 6206aba7..48fb5a85 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -1,23 +1,5 @@ """ Signal calculation module for far field - - consts.sim.FARFIELD_SIGNAL_MODEL : str - 'infinite_plane' (default/current behavior, dipole_dWdz -- two - infinite grounded planes, anode + cathode only) or 'box_lattice' - (image_lattice_dWdz -- adds grounded side-wall reflections). - Only affects calculate_ff_segments; calculate_ff_voxels is - unchanged and always uses dipole_dWdz. - - consts.ff_induction.LATTICE_LX, LATTICE_LY : float - Box half-widths for the grounded side walls (x=+/-LATTICE_LX, - y=+/-LATTICE_LY), analogous to BOX_LX/BOX_LY in - hybrid_pixel_response_boxed.py. - - consts.ff_induction.LATTICE_N_TERMS_XY : int - Number of side-wall image reflections per direction (total - (2*LATTICE_N_TERMS_XY+1)**2 lattice points evaluated per - cathode image). ff_induction.DIPOLE_N_TERMS is reused for the - cathode/z-image degree, same as in calculate_ff_segments. """ from functools import lru_cache @@ -194,119 +176,6 @@ def calculate_ff_segments( l = abs(z_cathode - z_anode) exclude_radius = (0.5 + ff_induction.CHARGE_NEIGHBOR_RADIUS) * detector.PIXEL_PITCH - for s_idx in range(n_segments): - segment = tracks[s_idx] - x0 = segment['x_start'] - y0 = segment['y_start'] - z0_seg = segment['z_start'] - x1 = segment['x_end'] - y1 = segment['y_end'] - z1 = segment['z_end'] - - # skip before splitting into sub-pieces. - if exclude_radius > 0.0: - dx0 = abs(x0 - x_pixel) - dy0 = abs(y0 - y_pixel) - dx1 = abs(x1 - x_pixel) - dy1 = abs(y1 - y_pixel) - if max(dx0, dx1) <= exclude_radius and max(dy0, dy1) <= exclude_radius: - continue - - vx = x1 - x0 - vy = y1 - y0 - vz = z1 - z0_seg - seg_len_sq = vx*vx + vy*vy + vz*vz - if seg_len_sq <= 1e-20: - continue - seg_len = math.sqrt(seg_len_sq) - - n_split, step = 1, ff_induction.FAR_FIELD_SEGMENT_STEP_CM - if step > 0.0: - n_split = max(int(math.ceil(seg_len / step)), 1) - - q_piece = segment['n_electrons'] / n_split - - for i_split in range(n_split): - frac = (i_split + 0.5) / n_split - x = x0 + frac * vx - y = y0 + frac * vy - z_start_piece = z0_seg + frac * vz - - # far-field exclusion radius - if exclude_radius > 0.0: - dx_xy = abs(x - x_pixel) - dy_xy = abs(y - y_pixel) - if dx_xy <= exclude_radius and dy_xy <= exclude_radius: - continue - - drift_distance = detector.V_DRIFT * t - if z_start_piece > z_anode: - z = z_start_piece - drift_distance - if z < z_anode: - continue - else: - z = z_start_piece + drift_distance - if z > z_anode: - continue - - dx = x - x_pixel - dy = y - y_pixel - dz = z - z_anode - - # C = ff_induction.DIPOLE_SCALE - # dWdz = C * dipole_dWdz(dx, dy, dz, l, ff_induction.DIPOLE_N_TERMS) - pix_halfw = 0.18 - dWdz = near_field_dWdz(dx, dy, dz, pix_halfw, pix_halfw, l, - ff_induction.DIPOLE_N_TERMS) - - total_current += -q_piece * detector.V_DRIFT * dWdz - - output[p_idx, t_idx] = total_current - - -@cuda.jit -def calculate_ff_segments_box_lattice( - tracks: cpt.NDArray, - pixel_x: cpt.NDArray[cp.float32], - pixel_y: cpt.NDArray[cp.float32], - z_anode: float, - z_cathode: float, - output: cp.ndarray[tuple[int, int], cp.float32] -): - """ - CUDA kernel: Calculate far-field induced current using segments, - with the box-aware image-lattice far field (image_lattice_dWdz) in - place of the infinite-plane dipole (dipole_dWdz). - - Identical to calculate_ff_segments() in every respect (exclusion - handling, segment splitting, drift geometry) except the per-piece - dW/dz calculation, which additionally reflects images off grounded - side walls at x=+/-ff_induction.LATTICE_LX, y=+/-ff_induction.LATTICE_LY - (see image_lattice_dWdz docstring). Selected via - sim.FARFIELD_SIGNAL_MODEL = 'box_lattice' in launch_ffe_kernel(). - - Args: - tracks: structured track array (fields: x_start, y_start, z_start, - x_end, y_end, z_end, n_electrons, pixel_plane, ...) - pixel_x/y: (n_pixels,) array of x/y-positions of each pixel's center - z_anode/cathode: Drift coordinate of the anode/cathode - output: (n_pixels, n_ticks) array of current signals - """ - p_idx, t_idx = cuda.grid(2) - n_pixels = pixel_x.shape[0] - n_ticks = output.shape[1] - if p_idx >= n_pixels or t_idx >= n_ticks: - return - - x_pixel = pixel_x[p_idx] - y_pixel = pixel_y[p_idx] - t = t_idx * detector.TIME_SAMPLING - total_current = 0.0 - - n_segments = tracks.shape[0] - l = abs(z_cathode - z_anode) - exclude_radius = ff_induction.CHARGE_NEIGHBOR_RADIUS * detector.PIXEL_PITCH - for s_idx in range(n_segments): segment = tracks[s_idx] x0 = segment['x_start'] @@ -367,11 +236,7 @@ def calculate_ff_segments_box_lattice( dz = z - z_anode C = ff_induction.DIPOLE_SCALE - C *= 0.01 # something something units - dWdz = C * image_lattice_dWdz( - dx, dy, dz, l, - ff_induction.LATTICE_LX, ff_induction.LATTICE_LY, - ff_induction.DIPOLE_N_TERMS, ff_induction.LATTICE_N_TERMS_XY) + dWdz = C * dipole_dWdz(dx, dy, dz, l, ff_induction.DIPOLE_N_TERMS) total_current += -q_piece * detector.V_DRIFT * dWdz @@ -418,121 +283,6 @@ def dipole_dWdz(dx: float, dy: float, dz: float, l: float, n_terms: int) -> floa return term0 + term_sum -@nb.njit -def image_lattice_dWdz(dx: float, dy: float, dz: float, l: float, - Lx: float, Ly: float, n_terms_z: int, - n_terms_xy: int) -> float: - """ - Box-aware dipole field calculation: combines a cathode image series - with additional image reflections off grounded side walls at - x=+/-Lx, y=+/-Ly. - - The pixel/dipole sits at the box center (x=y=0 in pixel-relative - coordinates), so reflecting off a wall pair a distance L away - generates images at x = 2*j*L for every integer j, with alternating - sign (-1)**j (j=0 recovers the un-reflected term). Combining - independent reflections off the x- and y-walls gives a 2D lattice - of images with sign (-1)**(j+k), applied to *every* z-image. - - Args: - (dx, dy, dz): Vector from electron to pixel (test point - relative to the dipole), with the pixel taken as the box - center in x, y - l: Drift length (anode-cathode separation) - Lx, Ly: Box half-widths -- grounded walls at x=+/-Lx, y=+/-Ly - n_terms_z: Degree of the cathode image series (images at - dz + 2*n*l for n = -n_terms_z .. n_terms_z) - n_terms_xy: Degree of the side-wall image lattice in each of - x and y (total (2*n_terms_xy+1)**2 lattice points per - z-image) - - Returns: - Calculated Shockley-Ramo weighting field for the current - induced on the pixel, including both cathode and side-wall - image reflections - """ - total = 0.0 - for j in range(-n_terms_xy, n_terms_xy + 1): - dx_j = dx - 2 * j * Lx - for k in range(-n_terms_xy, n_terms_xy + 1): - dy_k = dy - 2 * k * Ly - sign = 1.0 if (j + k) % 2 == 0 else -1.0 - - # Cathode (z) image series, linear 2*n*l spacing (matches - # far_field_image_lattice_potential), reflected off the - # same x/y wall lattice - for n in range(-n_terms_z, n_terms_z + 1): - dz_n = dz + 2 * n * l - r_sq = dx_j*dx_j + dy_k*dy_k + dz_n*dz_n - if r_sq > 1e-20: - r = math.sqrt(r_sq) - total += sign * (r_sq - 3.0*dz_n*dz_n) / (r_sq*r_sq*r) - return total - - -@nb.njit -def _corner_angle_dz(a: float, b: float, zpos: float) -> float: - """d/dzpos of _corner_angle(a, b, zpos), holding a, b fixed. - - _corner_angle(a, b, zpos) = arctan2(u, v) with u = a*b (independent - of zpos) and v = zpos*r, r = sqrt(a^2+b^2+zpos^2). Using - d/dt atan2(u, v) = (v u' - u v') / (u^2 + v^2), and u' = 0 here, - this reduces to -u v' / (u^2 + v^2), with - v' = dv/dzpos = r + zpos^2/r = (a^2+b^2+2*zpos^2) / r. - """ - r = math.sqrt(a**2 + b**2 + zpos**2) - u = a * b - v = zpos * r - dv_dzpos = (a**2 + b**2 + 2.0 * zpos**2) / r - return -u * dv_dzpos / (u**2 + v**2) - - -@nb.njit -def _patch_solid_angle_potential_dz(x: float, y: float, z: float, - wx: float, wy: float) -> float: - """d/dzpos of _patch_solid_angle_potential(x, y, zpos, wx, wy), - for zpos > 0 (same convention/singularity guard as that function).""" - x1, x2 = -wx - x, wx - x - y1, y2 = -wy - y, wy - y - domega = (_corner_angle_dz(x2, y2, z) - - _corner_angle_dz(x1, y2, z) - - _corner_angle_dz(x2, y1, z) - + _corner_angle_dz(x1, y1, z)) - return domega / (2.0 * np.pi) - - -@nb.njit -def near_field_dWdz(dx: float, dy: float, dz: float, - wx: float, wy: float, l: float, n_terms: int) \ - -> float: - """Analytic dW/dz of near_field_potential -- the z-component of the - exact finite-size-pixel weighting field, for direct use in place of - finite-differencing near_field_potential. - - Derivation: _patch_signed(x,y,z,wx,wy,z_src) = sign(zz) * g(|zz|) - with zz = z - z_src and g = _patch_solid_angle_potential(x,y,.,wx,wy). - Since d|zz|/dz = sign(zz), the chain rule gives - d/dz [sign(zz) * g(|zz|)] = sign(zz) * g'(|zz|) * sign(zz) - = g'(|zz|) - i.e. the sign(zz) factors cancel and the derivative is just the - *unsigned* zpos-derivative of the solid-angle formula (see - _patch_solid_angle_potential_dz), evaluated at |zz|, for every - image term -- no explicit sign/odd-extension bookkeeping needed - here (verified numerically against central differences of - near_field_potential to ~1e-10 relative error, both within and - across image planes). - - Only the z-component is provided (no dW/dx, dW/dy), matching - dipole_dWdz / image_lattice_dWdz in larndsim_ffe_signal.py, since - the simulated drift is purely along z. - """ - total = 0 - for n in range(-n_terms, n_terms + 1): - total += _patch_solid_angle_potential_dz( - dx, dy, abs(dz - 2 * n * l), wx, wy) - return total - - def launch_ffe_kernel( tpc_idx: int, tracks: cpt.NDArray, @@ -600,8 +350,6 @@ def launch_segments(kernel): match sim.FARFIELD_SIGNAL_MODEL: case 'infinite_plane': launch_segments(calculate_ff_segments) - case 'box_lattice': - launch_segments(calculate_ff_segments_box_lattice) case _: e = f"Invalid farfield_signal_model '{sim.FARFIELD_SIGNAL_MODEL}'" raise RuntimeError(e) From 188710e622f2d25ceafbf27e099e2b8f2d78467c Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 8 Oct 2026 06:59:35 +0200 Subject: [PATCH 53/60] Revert "test: mark charge/neighbor pix as induction-only" This reverts commit 5d14b61a7516f79c41f17038ec6681d9b902ef3e. --- larndsim/far_field/pixel_classifier.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/larndsim/far_field/pixel_classifier.py b/larndsim/far_field/pixel_classifier.py index f4f20407..cfb98632 100644 --- a/larndsim/far_field/pixel_classifier.py +++ b/larndsim/far_field/pixel_classifier.py @@ -236,17 +236,17 @@ def classify_pixels_kernel( thresholds_neighbor = ff_induction.CHARGE_NEIGHBOR_RADIUS * detector.PIXEL_PITCH r_eff_neighbor = thresholds_neighbor + detector.DIFF_N_SIGMAS * sigma_T - # # Check charge collection first (highest priority) - # if r_trans <= r_eff_cc: - # pixel_category = PixelCategory.CHARGE_COLLECTION - # break # Can't get higher priority, stop checking - - # # Check charge neighbor - # if r_trans <= r_eff_neighbor: - # # Upgrade if we're currently INACTIVE or INDUCTION_ONLY - # if pixel_category < PixelCategory.CHARGE_NEIGHBOR: - # pixel_category = PixelCategory.CHARGE_NEIGHBOR - # continue + # Check charge collection first (highest priority) + if r_trans <= r_eff_cc: + pixel_category = PixelCategory.CHARGE_COLLECTION + break # Can't get higher priority, stop checking + + # Check charge neighbor + if r_trans <= r_eff_neighbor: + # Upgrade if we're currently INACTIVE or INDUCTION_ONLY + if pixel_category < PixelCategory.CHARGE_NEIGHBOR: + pixel_category = PixelCategory.CHARGE_NEIGHBOR + continue # Accumulate induction signal (lowest priority) # We accumulate from all segments, then check threshold at the end From 2b195726b23971de234aabf816bec657e8da59a5 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 8 Oct 2026 07:48:34 +0200 Subject: [PATCH 54/60] Move FARFIELD_MODE and FARFIELD_SIGNAL_MODEL --- cli/simulate_pixels.py | 6 +++--- larndsim/consts/ff_induction.py | 22 +++++++++++++++++++++- larndsim/consts/sim.py | 16 ---------------- larndsim/far_field/signal_calculation.py | 8 ++++---- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index 8218185f..c1be6b68 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -686,7 +686,7 @@ def run_simulation(input_filename, importlib.reload(fee) if sim.FARFIELD_ENABLED: - print("Far-field mode:", sim.FARFIELD_MODE) + print("Far-field mode:", ff_induction.FARFIELD_MODE) if farfield_properties: print(f"Far-field properties file: {farfield_properties}") else: @@ -697,7 +697,7 @@ def run_simulation(input_filename, else: print("No far-field properties file specified; using default properties") - print("Dipole method:", sim.FARFIELD_SIGNAL_MODEL) + print("Dipole method:", ff_induction.FARFIELD_SIGNAL_MODEL) #if light.LIGHT_TRIG_MODE == 1 and not sim.IS_SPILL_SIM: @@ -1291,7 +1291,7 @@ def digitize_and_update(*args, **kwargs): if sim.FARFIELD_ENABLED: classification_cache = \ pixel_classifier.get_classification_cache(all_selected_tracks) - if sim.FARFIELD_MODE == 'voxels': + if ff_induction.FARFIELD_MODE == 'voxels': voxel_cache = voxelization.get_voxel_cache(all_selected_tracks) RangePop() diff --git a/larndsim/consts/ff_induction.py b/larndsim/consts/ff_induction.py index 6bbadf3d..63f43ae5 100644 --- a/larndsim/consts/ff_induction.py +++ b/larndsim/consts/ff_induction.py @@ -6,6 +6,12 @@ from .units import cm +#: Whether to use segments or voxels for FFE +FARFIELD_MODE = 'segments' + +#: Model to use for the induced current +FARFIELD_SIGNAL_MODEL = 'infinite_plane' + ################### # Voxel Resolution ################### @@ -42,7 +48,7 @@ DIPOLE_N_TERMS = 5 # Normalization constant for dipole; found empirically -# ~1.50 for infinite-plane dipole +# ~1.50 for infinite-plane dipole in FSD Cube DIPOLE_SCALE = 1.5 @@ -52,6 +58,8 @@ def set_ff_induction_properties(ffprop_file: str): Args: ffprop_file: YAML filename """ + global FARFIELD_MODE + global FARFIELD_SIGNAL_MODEL global COARSE_VOXEL_SIZE_X global COARSE_VOXEL_SIZE_Y global COARSE_VOXEL_SIZE_Z @@ -66,6 +74,18 @@ def set_ff_induction_properties(ffprop_file: str): with open(ffprop_file) as df: ffprop = yaml.load(df, Loader=yaml.FullLoader) + FARFIELD_MODE = ffprop.get('farfield_mode', FARFIELD_MODE) + options = ['segments', 'voxels'] + if FARFIELD_MODE not in options: + raise RuntimeError(f"Invalid farfield_mode {FARFIELD_MODE}; " + + f"must be one of {options}") + + FARFIELD_SIGNAL_MODEL = ffprop.get('farfield_signal_model', FARFIELD_SIGNAL_MODEL) + options = ['infinite_plane'] + if FARFIELD_SIGNAL_MODEL not in options: + raise RuntimeError(f"Invalid farfield_signal_model {FARFIELD_SIGNAL_MODEL}; " + + f"must be one of {options}") + COARSE_VOXEL_SIZE_X = ffprop.get('coarse_voxel_size_x', COARSE_VOXEL_SIZE_X) COARSE_VOXEL_SIZE_Y = ffprop.get('coarse_voxel_size_y', COARSE_VOXEL_SIZE_Y) COARSE_VOXEL_SIZE_Z = ffprop.get('coarse_voxel_size_z', COARSE_VOXEL_SIZE_Z) diff --git a/larndsim/consts/sim.py b/larndsim/consts/sim.py index 6e5e5cea..7890a9c0 100644 --- a/larndsim/consts/sim.py +++ b/larndsim/consts/sim.py @@ -39,8 +39,6 @@ MC_TRUTH_THRESHOLD = 0.1 # pe/us lower is better, but memory usage increases FARFIELD_ENABLED = False -FARFIELD_MODE = 'segments' # 'segments' or 'voxels'; latter unvalidated -FARFIELD_SIGNAL_MODEL = 'infinite_plane' def set_simulation_properties(simprop_file): """ @@ -73,8 +71,6 @@ def set_simulation_properties(simprop_file): global MC_TRUTH_THRESHOLD global FARFIELD_ENABLED - global FARFIELD_MODE - global FARFIELD_SIGNAL_MODEL with open(simprop_file) as df: simprop = yaml.load(df, Loader=yaml.FullLoader) @@ -98,15 +94,3 @@ def set_simulation_properties(simprop_file): MC_TRUTH_THRESHOLD = simprop.get('mc_truth_threshold', MC_TRUTH_THRESHOLD) FARFIELD_ENABLED = bool(simprop.get('farfield_enabled', FARFIELD_ENABLED)) - - FARFIELD_MODE = simprop.get('farfield_mode', FARFIELD_MODE) - options = ['segments', 'voxels'] - if FARFIELD_MODE not in options: - raise RuntimeError(f"Invalid farfield_mode {FARFIELD_MODE}; " + - f"must be one of {options}") - - FARFIELD_SIGNAL_MODEL = simprop.get('farfield_signal_model', FARFIELD_SIGNAL_MODEL) - options = ['infinite_plane'] - if FARFIELD_SIGNAL_MODEL not in options: - raise RuntimeError(f"Invalid farfield_signal_model {FARFIELD_SIGNAL_MODEL}; " + - f"must be one of {options}") diff --git a/larndsim/far_field/signal_calculation.py b/larndsim/far_field/signal_calculation.py index 48fb5a85..d9f2d313 100644 --- a/larndsim/far_field/signal_calculation.py +++ b/larndsim/far_field/signal_calculation.py @@ -343,18 +343,18 @@ def launch_segments(kernel): pixel_x, pixel_y, z_anode, z_cathode, output) - match sim.FARFIELD_MODE: + match ff_induction.FARFIELD_MODE: case 'voxels': launch_voxels() case 'segments': - match sim.FARFIELD_SIGNAL_MODEL: + match ff_induction.FARFIELD_SIGNAL_MODEL: case 'infinite_plane': launch_segments(calculate_ff_segments) case _: - e = f"Invalid farfield_signal_model '{sim.FARFIELD_SIGNAL_MODEL}'" + e = f"Invalid farfield_signal_model '{ff_induction.FARFIELD_SIGNAL_MODEL}'" raise RuntimeError(e) case _: - e = f"Invalid farfield_mode '{sim.FARFIELD_MODE}'" + e = f"Invalid farfield_mode '{ff_induction.FARFIELD_MODE}'" raise RuntimeError(e) return output From 0facc8cbc48e2ddb83904dee90fc3f0affa8fc28 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 8 Oct 2026 07:50:59 +0200 Subject: [PATCH 55/60] Enable FFE for FSD Cube --- larndsim/config/config.yaml | 3 ++- larndsim/farfield_properties/ff_fsdcube.yaml | 1 + larndsim/simulation_properties/cosmic_sim_FFE.yaml | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 larndsim/farfield_properties/ff_fsdcube.yaml create mode 100644 larndsim/simulation_properties/cosmic_sim_FFE.yaml diff --git a/larndsim/config/config.yaml b/larndsim/config/config.yaml index 293ebb6c..cdf41274 100644 --- a/larndsim/config/config.yaml +++ b/larndsim/config/config.yaml @@ -124,7 +124,7 @@ fsd_lut_fp16: LIGHT_LUT: /dvs_ro/cfs/cdirs/dune/www/data/2x2/simulation/larndsim_data/light_LUT/lightLUT_FSD_250123_time_norm_fp16.npz fsd_cube: - SIM_PROPERTIES: cosmic_sim.yaml + SIM_PROPERTIES: cosmic_sim_FFE.yaml PIXEL_LAYOUT: multi_tile_layout-3.0.40_fsdcube.yaml DET_PROPERTIES: fsd_cube.yaml #RESPONSE: /dvs_ro/cfs/projectdirs/dune/www/data/2x2/simulation/larndsim_data/pixel_response/response_fsdcube_v2d_full_25x25pixel_250Vcm.npz @@ -133,6 +133,7 @@ fsd_cube: PIXEL_THRESHOLDS_ID: [0] PIXEL_PEDESTALS_FILE: [pedestals_fsdcube.npz] PIXEL_PEDESTALS_ID: [0] + FARFIELD_PROPERTIES: 'ff_fsdcube.yaml' LIGHT_LUT: /dvs_ro/cfs/cdirs/dune/www/data/2x2/simulation/larndsim_data/light_LUT/lightLUT_FSD_250123_time_norm.npz LIGHT_DET_NOISE: FSD_v01_bin06_larndsim_noise.npy LIGHT_SIMULATED: False diff --git a/larndsim/farfield_properties/ff_fsdcube.yaml b/larndsim/farfield_properties/ff_fsdcube.yaml new file mode 100644 index 00000000..5cff124b --- /dev/null +++ b/larndsim/farfield_properties/ff_fsdcube.yaml @@ -0,0 +1 @@ +dipole_scale: 1.5 diff --git a/larndsim/simulation_properties/cosmic_sim_FFE.yaml b/larndsim/simulation_properties/cosmic_sim_FFE.yaml new file mode 100644 index 00000000..a8b2077c --- /dev/null +++ b/larndsim/simulation_properties/cosmic_sim_FFE.yaml @@ -0,0 +1,12 @@ +segment_batch_size: 10000 # track segments +event_batch_size: 2 # tpcs +write_batch_size: 1 # batches +is_spill_sim: 0 # boolean +event_separator: 'event_id' # 'eventID' +tracks_dset_name: 'segments' # or 'segments' +max_events_per_file: 10000 + +max_light_truth_ids: 50 # set to zero to disable light truth backtracking +mc_truth_threshold: 0.1 # pe/us + +farfield_enabled: True From 7937e9d169518dc2cc402c6c1ca03ae5f9bd29f0 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Thu, 8 Oct 2026 09:12:53 +0200 Subject: [PATCH 56/60] Remove duplicate print --- cli/simulate_pixels.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cli/simulate_pixels.py b/cli/simulate_pixels.py index c1be6b68..327baa09 100644 --- a/cli/simulate_pixels.py +++ b/cli/simulate_pixels.py @@ -692,11 +692,6 @@ def run_simulation(input_filename, else: print("No far-field properties file specified; using default properties") - if farfield_properties: - print(f"Far-field properties file: {farfield_properties}") - else: - print("No far-field properties file specified; using default properties") - print("Dipole method:", ff_induction.FARFIELD_SIGNAL_MODEL) From 033ffbddf53dcda2ecf36cc6d2495939ede3887e Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Wed, 14 Oct 2026 14:11:22 -0700 Subject: [PATCH 57/60] Use /dvs_ro, not /global, for fsdcube response --- larndsim/config/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larndsim/config/config.yaml b/larndsim/config/config.yaml index cdf41274..b94c4770 100644 --- a/larndsim/config/config.yaml +++ b/larndsim/config/config.yaml @@ -128,7 +128,7 @@ fsd_cube: PIXEL_LAYOUT: multi_tile_layout-3.0.40_fsdcube.yaml DET_PROPERTIES: fsd_cube.yaml #RESPONSE: /dvs_ro/cfs/projectdirs/dune/www/data/2x2/simulation/larndsim_data/pixel_response/response_fsdcube_v2d_full_25x25pixel_250Vcm.npz - RESPONSE: /global/cfs/projectdirs/dune/www/data/2x2/simulation/larndsim_data/pixel_response/response_fsdcube_v2d_full_9x9pixel_250Vcm.npz + RESPONSE: /dvs_ro/cfs/projectdirs/dune/www/data/2x2/simulation/larndsim_data/pixel_response/response_fsdcube_v2d_full_9x9pixel_250Vcm.npz PIXEL_THRESHOLDS_FILE: [thresholds_fsdcube.npz] PIXEL_THRESHOLDS_ID: [0] PIXEL_PEDESTALS_FILE: [pedestals_fsdcube.npz] From 2a9a1e29ecd0b2d30bddbdd8773b395e85bb664a Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Wed, 14 Oct 2026 14:11:51 -0700 Subject: [PATCH 58/60] Set charge_neighbor_radius to 4 for fsdcube --- larndsim/farfield_properties/ff_fsdcube.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/larndsim/farfield_properties/ff_fsdcube.yaml b/larndsim/farfield_properties/ff_fsdcube.yaml index 5cff124b..768d50b0 100644 --- a/larndsim/farfield_properties/ff_fsdcube.yaml +++ b/larndsim/farfield_properties/ff_fsdcube.yaml @@ -1 +1,2 @@ dipole_scale: 1.5 +charge_neighbor_radius: 4 From 416f5fc15cd6ea3a34cda1b911ad182c4ff8a1c0 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Wed, 14 Oct 2026 14:12:57 -0700 Subject: [PATCH 59/60] Set default charge_neighbor_radius to 4 --- larndsim/consts/ff_induction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larndsim/consts/ff_induction.py b/larndsim/consts/ff_induction.py index 63f43ae5..30e36e28 100644 --- a/larndsim/consts/ff_induction.py +++ b/larndsim/consts/ff_induction.py @@ -33,7 +33,7 @@ CHARGE_COLLECTION_RADIUS = 1 # pixels # Neighbor pixel radius -CHARGE_NEIGHBOR_RADIUS = 2 # pixels +CHARGE_NEIGHBOR_RADIUS = 4 # pixels # Maximum induction consideration distance INDUCTION_CUTOFF_RADIUS = 50 # cm From 5ebb8fec2ba0b7fcf17f9316dccf072ed09665a4 Mon Sep 17 00:00:00 2001 From: Matt Kramer Date: Wed, 14 Oct 2026 15:05:53 -0700 Subject: [PATCH 60/60] Restore lost factor of 1/100 in DIPOLE_SCALE --- larndsim/consts/ff_induction.py | 4 ++-- larndsim/farfield_properties/ff_fsdcube.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/larndsim/consts/ff_induction.py b/larndsim/consts/ff_induction.py index 30e36e28..1f1ef8f1 100644 --- a/larndsim/consts/ff_induction.py +++ b/larndsim/consts/ff_induction.py @@ -48,8 +48,8 @@ DIPOLE_N_TERMS = 5 # Normalization constant for dipole; found empirically -# ~1.50 for infinite-plane dipole in FSD Cube -DIPOLE_SCALE = 1.5 +# ~0.0150 for infinite-plane dipole in FSD Cube +DIPOLE_SCALE = 0.015 def set_ff_induction_properties(ffprop_file: str): diff --git a/larndsim/farfield_properties/ff_fsdcube.yaml b/larndsim/farfield_properties/ff_fsdcube.yaml index 768d50b0..66efe57d 100644 --- a/larndsim/farfield_properties/ff_fsdcube.yaml +++ b/larndsim/farfield_properties/ff_fsdcube.yaml @@ -1,2 +1,2 @@ -dipole_scale: 1.5 +dipole_scale: 0.015 charge_neighbor_radius: 4