Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disabled channels filter #166

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/proto_nd_flow/disabled_channels_2x2.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/proto_nd_flow/reco/charge/raw_event_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ def next(self):
else:
mc_assn = None

mask = (block['valid_parity'].astype(bool) & (block['packet_type'] == 0)) # data packets
mask_disabled_channels = np.array(
[(p[['io_group', 'io_channel', 'chip_id', 'channel_id']]) not in resources['Geometry'].disabled_channels for p in block]
, dtype=bool)
mask = (block['valid_parity'].astype(bool) & (block['packet_type'] == 0) & mask_disabled_channels) # data packets
mask = mask | (block['packet_type'] == 4) # timestamp packets
mask = mask | (block['packet_type'] == 7) # external trigger packets
mask = mask | (block['packet_type'] == 6) # sync packets
Expand Down
45 changes: 45 additions & 0 deletions src/proto_nd_flow/resources/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import warnings
import yaml
import json

from h5flow.core import H5FlowResource
from h5flow.core import resources
Expand Down Expand Up @@ -89,6 +90,7 @@ class Geometry(H5FlowResource):
default_det_geometry_file = '-'
default_crs_geometry_file = ['-']
default_lrs_geometry_file = '-'
default_disabled_channels_file = '-'
default_beam_direction = 'z'
default_drift_direction = 'x'
default_crs_geometry_to_module = [0]
Expand All @@ -102,6 +104,7 @@ def __init__(self, **params):
self.charge_only = params.get('charge_only', self.default_charge_only)
self.n_io_channels_per_tile = params.get('n_io_channels_per_tile', self.default_n_io_channels_per_tile)
self.crs_geometry_files = params.get('crs_geometry_files', self.default_crs_geometry_file)
self.disabled_channels_file = params.get('disabled_channels_file', self.default_disabled_channels_file)
self.crs_geometry_to_module = params.get('crs_geometry_to_module', self.default_crs_geometry_to_module)
self.det_geometry_file = params.get('det_geometry_file', self.default_det_geometry_file)
self.lrs_geometry_file = params.get('lrs_geometry_file', self.default_lrs_geometry_file)
Expand All @@ -111,6 +114,7 @@ def __init__(self, **params):
self._lar_detector_bounds = None # min and max xyz coordinates for full LAr detector
self._max_drift_distance = None # max drift distance in each LArTPC (2 TPCs per module)
self._module_RO_bounds = None # min and max xyz coordinates for each pixel LArTPC module
self._disabled_channels = None

def init(self, source_name):
super(Geometry, self).init(source_name)
Expand Down Expand Up @@ -155,6 +159,10 @@ def init(self, source_name):
write_lut(self.data_manager, self.path, self.pixel_coordinates_2D, 'pixel_coordinates_2D')
write_lut(self.data_manager, self.path, self.tile_id, 'tile_id')

self.data_manager.create_dset(self.path+'/disabled_channels', dtype=self.disabled_channels.dtype)
disabled_channels_slice = self.data_manager.reserve_data(self.path+'/disabled_channels', len(self.disabled_channels))
self.data_manager.write_data(self.path+'/disabled_channels', disabled_channels_slice, self.disabled_channels)

if not self.charge_only:
self.data_manager.set_attrs(self.path, lrs_geometry_file=self.lrs_geometry_file)
write_lut(self.data_manager, self.path, self.det_rel_pos, 'det_rel_pos')
Expand All @@ -171,6 +179,7 @@ def init(self, source_name):
self._max_drift_distance = self.data['max_drift_distance']
self._module_RO_bounds = self.data['module_RO_bounds']
self._pixel_pitch = self.data['pixel_pitch']
self._disabled_channels = self.data_manager.get_dset(self.path+'/disabled_channels')

self._anode_drift_coordinate = read_lut(self.data_manager, self.path, 'anode_drift_coordinate')
self._drift_dir = read_lut(self.data_manager, self.path, 'drift_dir')
Expand Down Expand Up @@ -422,6 +431,9 @@ def _get_module_RO_bounds(self):

self._module_RO_bounds = np.array(self._module_RO_bounds)

@property
def disabled_channels(self):
return self._disabled_channels

@staticmethod
def _rotate_pixel(pixel_pos, tile_orientation):
Expand Down Expand Up @@ -850,3 +862,36 @@ def _load_charge_geometry(self):
# self._cathode_thickness = abs(anode_to_cathode - self.max_drift_distance) * 2.0
#else:
# self._cathode_thickness = 0.0

self._load_disabled_channels()

def _load_disabled_channels(self):

# Parses the disabled channels file into a structured array.
# The first iteration of the file is a json dictionary where the keys are strings
# '<io_group>-<io_channel>-<chip_id>' and the values are lists of the channel_ids

disabled_channels_dtype = np.dtype([
('io_group', 'u8'),
('io_channel', 'u8'),
('chip_id', 'u8'),
('channel_id', 'u8')
])

disabled_channels_list = []
if self.disabled_channels_file == '-':
self._disabled_channels = np.array([], dtype = disabled_channels_dtype)
return

with open(self.disabled_channels_file, 'r') as f:
disabled_channels_json = json.load(f)

for key in disabled_channels_json:

io_group, io_channel, chip_id = key.split('-')

for channel_id in disabled_channels_json[key]:

disabled_channels_list.append((int(io_group), int(io_channel), int(chip_id), int(channel_id)))

self._disabled_channels = np.array(disabled_channels_list, dtype = disabled_channels_dtype)
1 change: 1 addition & 0 deletions yamls/proto_nd_flow/resources/GeometryMC.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ params:
'data/proto_nd_flow/multi_tile_layout-2.5.16_v3.yaml']
crs_geometry_to_module: [0,0,1,0]
lrs_geometry_file: 'data/proto_nd_flow/light_module_desc-4.0.0.yaml'
disabled_channels_file: 'data/proto_nd_flow/disabled_channels_2x2.json'
beam_direction: 'z'
drift_direction: 'x'
network_agnostic: true
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ flow:

resources:
- !include yamls/proto_nd_flow/resources/RunDataMC.yaml

- !include yamls/proto_nd_flow/resources/GeometryMC.yaml

raw_event_generator: # groups time-sorted data packets from larpix datalog files
!include yamls/proto_nd_flow/reco/charge/RawEventGeneratorMC.yaml