diff --git a/examples/MapPixelIDToUniqueID_2x2.ipynb b/examples/MapPixelIDToUniqueID_2x2.ipynb index e6e2b2e1..2d7a1d5b 100644 --- a/examples/MapPixelIDToUniqueID_2x2.ipynb +++ b/examples/MapPixelIDToUniqueID_2x2.ipynb @@ -57,8 +57,8 @@ "metadata": {}, "outputs": [], "source": [ - "_default_geometry_yaml = '../larndsim/pixel_layouts/multi_tile_layout-2.4.16_v4.yaml'\n", - "_default_geometry_yaml_mod2 = '../larndsim/pixel_layouts/multi_tile_layout-2.5.16_v4.yaml'\n", + "# _default_geometry_yaml = '../larndsim/pixel_layouts/multi_tile_layout-2.4.16_v4.yaml'\n", + "# _default_geometry_yaml_mod2 = '../larndsim/pixel_layouts/multi_tile_layout-2.5.16_v4.yaml'\n", "\n", "def _default_pxy():\n", " return (0., 0.)\n", @@ -69,152 +69,76 @@ "\n", "\n", "cmap = cm.viridis_r\n", - "pixel_pitch = 1\n", + "# pixel_pitch = 1\n", "\n", - "geometry_yaml = _default_geometry_yaml\n", - "with open(geometry_yaml) as fi:\n", - " geo = yaml.full_load(fi)\n", - "\n", - "\n", - "geometry_yaml_mod2 = _default_geometry_yaml_mod2\n", - "with open(geometry_yaml_mod2) as fi2:\n", - " geo_mod2 = yaml.full_load(fi2)\n", - "\n", - "# Module 1, 3, 4 layout\n", - "pixel_pitch = geo['pixel_pitch']\n", - "\n", - "chip_channel_to_position = geo['chip_channel_to_position']\n", - "tile_orientations = geo['tile_orientations']\n", - "tile_positions = geo['tile_positions']\n", - "tpc_centers = geo['tpc_centers']\n", - "tile_indeces = geo['tile_indeces']\n", - "xs = np.array(list(chip_channel_to_position.values()))[\n", - " :, 0] * pixel_pitch\n", - "ys = np.array(list(chip_channel_to_position.values()))[\n", - " :, 1] * pixel_pitch\n", - "x_size = max(xs)-min(xs)+pixel_pitch\n", - "y_size = max(ys)-min(ys)+pixel_pitch\n", - "\n", - "tile_geometry = defaultdict(int)\n", - "io_group_io_channel_to_tile = {}\n", - "geometry = defaultdict(_default_pxy)\n", - "\n", - "for tile in geo['tile_chip_to_io']:\n", - " tile_orientation = tile_orientations[tile]\n", - " tile_geometry[tile] = tile_positions[tile], tile_orientations[tile]\n", - " for chip in geo['tile_chip_to_io'][tile]:\n", - " io_group_io_channel = geo['tile_chip_to_io'][tile][chip]\n", - " io_group = io_group_io_channel//1000\n", - " io_channel = io_group_io_channel % 1000\n", - " io_group_io_channel_to_tile[(\n", - " io_group, io_channel)] = tile\n", - "\n", - " for chip_channel in geo['chip_channel_to_position']:\n", - " chip = chip_channel // 1000\n", - " channel = chip_channel % 1000\n", - " try:\n", - " io_group_io_channel = geo['tile_chip_to_io'][tile][chip]\n", - " except KeyError:\n", - " print(\"Chip %i on tile %i not present in network\" %\n", - " (chip, tile))\n", - " continue\n", - "\n", - " io_group = io_group_io_channel // 1000\n", - " io_channel = io_group_io_channel % 1000\n", - " x = chip_channel_to_position[chip_channel][0] * \\\n", - " pixel_pitch + pixel_pitch / 2 - x_size / 2\n", - " y = chip_channel_to_position[chip_channel][1] * \\\n", - " pixel_pitch + pixel_pitch / 2 - y_size / 2\n", - "\n", - " x, y = _rotate_pixel((x, y), tile_orientation)\n", - " x += tile_positions[tile][2] + \\\n", - " tpc_centers[tile_indeces[tile][0]][0]\n", - " y += tile_positions[tile][1] + \\\n", - " tpc_centers[tile_indeces[tile][0]][1]\n", - "\n", - " geometry[(io_group, io_group_io_channel_to_tile[(\n", - " io_group, io_channel)], chip, channel)] = x, y\n", - "\n", - "xmin = min(np.array(list(geometry.values()))[:, 0])-pixel_pitch/2\n", - "xmax = max(np.array(list(geometry.values()))[:, 0])+pixel_pitch/2\n", - "ymin = min(np.array(list(geometry.values()))[:, 1])-pixel_pitch/2\n", - "ymax = max(np.array(list(geometry.values()))[:, 1])+pixel_pitch/2\n", - "\n", - "tile_vertical_lines = np.linspace(xmin, xmax, 3)\n", - "tile_horizontal_lines = np.linspace(ymin, ymax, 5)\n", - "chip_vertical_lines = np.linspace(xmin, xmax, 21)\n", - "chip_horizontal_lines = np.linspace(ymin, ymax, 41)\n", - "\n", - "nonrouted_v2a_channels = [6, 7, 8, 9, 22,\n", - " 23, 24, 25, 38, 39, 40, 54, 55, 56, 57]\n", - "routed_v2a_channels = [i for i in range(\n", - " 64) if i not in nonrouted_v2a_channels]\n", - "\n", - "# Module 2 layout\n", - "pixel_pitch_mod2 = geo_mod2['pixel_pitch']\n", - "\n", - "chip_channel_to_position_mod2 = geo_mod2['chip_channel_to_position']\n", - "tile_orientations_mod2 = geo_mod2['tile_orientations']\n", - "tile_positions_mod2 = geo_mod2['tile_positions']\n", - "tpc_centers_mod2 = geo['tpc_centers']\n", - "tile_indeces_mod2 = geo_mod2['tile_indeces']\n", - "xs_mod2 = np.array(list(chip_channel_to_position_mod2.values()))[\n", - " :, 0] * pixel_pitch_mod2\n", - "ys_mod2 = np.array(list(chip_channel_to_position_mod2.values()))[\n", - " :, 1] * pixel_pitch_mod2\n", - "x_size_mod2 = max(xs_mod2)-min(xs_mod2)+pixel_pitch_mod2\n", - "y_size_mod2 = max(ys_mod2)-min(ys_mod2)+pixel_pitch_mod2\n", - "\n", - "tile_geometry_mod2 = defaultdict(int)\n", - "io_group_io_channel_to_tile_mod2 = {}\n", - "geometry_mod2 = defaultdict(_default_pxy)\n", - "\n", - "for tile in geo_mod2['tile_chip_to_io']:\n", - " tile_orientation_mod2 = tile_orientations_mod2[tile]\n", - " tile_geometry_mod2[tile] = tile_positions_mod2[tile], tile_orientations_mod2[tile]\n", - " for chip in geo_mod2['tile_chip_to_io'][tile]:\n", - " io_group_io_channel = geo_mod2['tile_chip_to_io'][tile][chip]\n", - " io_group = io_group_io_channel//1000\n", - " io_channel = io_group_io_channel % 1000\n", - " io_group_io_channel_to_tile_mod2[(\n", - " io_group, io_channel)] = tile\n", - "\n", - " for chip_channel in geo_mod2['chip_channel_to_position']:\n", - " chip = chip_channel // 1000\n", - " channel = chip_channel % 1000\n", - " try:\n", - " io_group_io_channel = geo_mod2['tile_chip_to_io'][tile][chip]\n", - " except KeyError:\n", - " print(\"Chip %i on tile %i not present in Module 2 network\" %\n", - " (chip, tile))\n", - " continue\n", - "\n", - " io_group = io_group_io_channel // 1000\n", - " io_channel = io_group_io_channel % 1000\n", - " x = chip_channel_to_position_mod2[chip_channel][0] * \\\n", - " pixel_pitch_mod2 + pixel_pitch_mod2 / 2 - x_size_mod2 / 2\n", - " y = chip_channel_to_position_mod2[chip_channel][1] * \\\n", - " pixel_pitch_mod2 + pixel_pitch_mod2 / 2 - y_size_mod2 / 2\n", - "\n", - " x, y = _rotate_pixel((x, y), tile_orientation_mod2)\n", - " x += tile_positions_mod2[tile][2] + \\\n", - " tpc_centers_mod2[tile_indeces_mod2[tile][0]][0]\n", - " y += tile_positions_mod2[tile][1] + \\\n", - " tpc_centers_mod2[tile_indeces_mod2[tile][0]][1]\n", - "\n", - " geometry_mod2[(io_group, io_group_io_channel_to_tile_mod2[(\n", - " io_group, io_channel)], chip, channel)] = x, y\n", - "\n", - "xmin_mod2 = min(np.array(list(geometry_mod2.values()))\n", - " [:, 0])-pixel_pitch_mod2/2\n", - "xmax_mod2 = max(np.array(list(geometry_mod2.values()))\n", - " [:, 0])+pixel_pitch_mod2/2\n", - "ymin_mod2 = min(np.array(list(geometry_mod2.values()))\n", - " [:, 1])-pixel_pitch_mod2/2\n", - "ymax_mod2 = max(np.array(list(geometry_mod2.values()))\n", - " [:, 1])+pixel_pitch_mod2/2\n", - "\n", - "# Plot metrics\n" + "class Geo:\n", + " def __init__(self, geometry_yaml):\n", + " with open(geometry_yaml) as fi:\n", + " geo = yaml.full_load(fi)\n", + " \n", + " self.pixel_pitch = geo['pixel_pitch']\n", + " \n", + " chip_channel_to_position = geo['chip_channel_to_position']\n", + " tile_orientations = geo['tile_orientations']\n", + " tile_positions = geo['tile_positions']\n", + " tpc_centers = geo['tpc_centers']\n", + " tile_indeces = geo['tile_indeces']\n", + " xs = np.array(list(chip_channel_to_position.values()))[\n", + " :, 0] * self.pixel_pitch\n", + " ys = np.array(list(chip_channel_to_position.values()))[\n", + " :, 1] * self.pixel_pitch\n", + " x_size = max(xs)-min(xs)+self.pixel_pitch\n", + " y_size = max(ys)-min(ys)+self.pixel_pitch\n", + " \n", + " tile_geometry = defaultdict(int)\n", + " io_group_io_channel_to_tile = {}\n", + " self.geometry = defaultdict(_default_pxy)\n", + " \n", + " for tile in geo['tile_chip_to_io']:\n", + " tile_orientation = tile_orientations[tile]\n", + " tile_geometry[tile] = tile_positions[tile], tile_orientations[tile]\n", + " for chip in geo['tile_chip_to_io'][tile]:\n", + " io_group_io_channel = geo['tile_chip_to_io'][tile][chip]\n", + " io_group = io_group_io_channel//1000\n", + " io_channel = io_group_io_channel % 1000\n", + " io_group_io_channel_to_tile[(\n", + " io_group, io_channel)] = tile\n", + " \n", + " for chip_channel in geo['chip_channel_to_position']:\n", + " chip = chip_channel // 1000\n", + " channel = chip_channel % 1000\n", + " try:\n", + " io_group_io_channel = geo['tile_chip_to_io'][tile][chip]\n", + " except KeyError:\n", + " print(\"Chip %i on tile %i not present in network\" %\n", + " (chip, tile))\n", + " continue\n", + " \n", + " io_group = io_group_io_channel // 1000\n", + " io_channel = io_group_io_channel % 1000\n", + " x = chip_channel_to_position[chip_channel][0] * \\\n", + " self.pixel_pitch + self.pixel_pitch / 2 - x_size / 2\n", + " y = chip_channel_to_position[chip_channel][1] * \\\n", + " self.pixel_pitch + self.pixel_pitch / 2 - y_size / 2\n", + " \n", + " x, y = _rotate_pixel((x, y), tile_orientation)\n", + " x += tile_positions[tile][2] + \\\n", + " tpc_centers[tile_indeces[tile][0]][0]\n", + " y += tile_positions[tile][1] + \\\n", + " tpc_centers[tile_indeces[tile][0]][1]\n", + " \n", + " self.geometry[(io_group, io_group_io_channel_to_tile[(\n", + " io_group, io_channel)], chip, channel)] = x, y\n", + " \n", + " self.xmin = min(np.array(list(self.geometry.values()))[:, 0])-self.pixel_pitch/2\n", + " self.xmax = max(np.array(list(self.geometry.values()))[:, 0])+self.pixel_pitch/2\n", + " self.ymin = min(np.array(list(self.geometry.values()))[:, 1])-self.pixel_pitch/2\n", + " self.ymax = max(np.array(list(self.geometry.values()))[:, 1])+self.pixel_pitch/2\n", + " \n", + " tile_vertical_lines = np.linspace(self.xmin, self.xmax, 3)\n", + " tile_horizontal_lines = np.linspace(self.ymin, self.ymax, 5)\n", + " chip_vertical_lines = np.linspace(self.xmin, self.xmax, 21)\n", + " chip_horizontal_lines = np.linspace(self.ymin, self.ymax, 41)\n" ] }, { @@ -224,32 +148,32 @@ "metadata": {}, "outputs": [], "source": [ - "def unique_id_to_pixel_id(un, is_mod2=False):\n", + "def unique_id_to_pixel_id(un, geometry_object):\n", " io_group = unique_to_io_group(un)\n", " tile = unique_to_io_channel(un)\n", " chip_id = unique_to_chip_id(un)\n", " channel_id = unique_to_channel_id(un)\n", "\n", - " pitch = pixel_pitch_mod2 if is_mod2 else pixel_pitch\n", + " pitch = geometry_object.pixel_pitch\n", "\n", - " gg = geometry_mod2 if is_mod2 else geometry\n", + " gg = geometry_object.geometry\n", "\n", " x, y = gg[(2 - (io_group % 2), tile + 8 * (1 - (io_group % 2)), chip_id, channel_id)]\n", "\n", - " x_min = xmin_mod2 if is_mod2 else xmin\n", - " x_max = xmax_mod2 if is_mod2 else xmax\n", + " x_min = geometry_object.xmin\n", + " x_max = geometry_object.xmax\n", " \n", - " y_min = ymin_mod2 if is_mod2 else ymin\n", - " y_max = ymax_mod2 if is_mod2 else ymax\n", + " y_min = geometry_object.ymin\n", + " y_max = geometry_object.ymax\n", "\n", " x_int = (x - x_min) / pitch - 0.5\n", " y_int = (y - y_min) / pitch - 0.5\n", "\n", " if abs(round(x_int) - x_int) > 0.05:\n", - " print(is_mod2)\n", + " # print(is_mod2)\n", " print('ERROR X: ', un, ' - ', round(x_int), ' vs ', x_int)\n", " if abs(round(y_int) - y_int) > 0.05:\n", - " print(is_mod2)\n", + " # print(is_mod2)\n", " print('ERROR Y: ', un, ' - ', round(y_int), ' vs ', y_int)\n", " \n", " if abs(round((x_max - x_min)/pitch) - (x_max - x_min)/pitch) > 0.05:\n", @@ -272,33 +196,39 @@ "outputs": [], "source": [ "# LArPix-v2a anodes\n", - "\n", - "pixelid_to_uniqueid = dict()\n", - "uniqueid_to_pixelid = dict()\n", "nonrouted_v2a_channels = [6, 7, 8, 9, 22, 23, 24, 25, 38, 39, 40, 54, 55, 56, 57]\n", "\n", - "for io_group in tqdm.tqdm(range(1, 3)):\n", - " for tile in range(1, 9):\n", - " for chip_id in range(11, 111):\n", - " for channel_id in range(64):\n", - " if io_group in [1, 2, 3, 4, 7, 8] and channel_id in nonrouted_v2a_channels:\n", - " continue\n", - " unique_id = ((io_group*10000+tile)*1000 + chip_id)*100 + channel_id\n", - " pixel_id = unique_id_to_pixel_id(unique_id, is_mod2=False)\n", "\n", - " if pixel_id in pixelid_to_uniqueid.keys():\n", - " print('DUPLICATE PIXEL ID')\n", - " print('pixel_id: ', pixel_id)\n", - " print('channel: ', (io_group, tile, chip_id, channel_id))\n", - " if channel_id in uniqueid_to_pixelid.keys():\n", - " print('DUPLICATE UNIQUE ID')\n", - " pixelid_to_uniqueid[pixel_id] = unique_id\n", - " uniqueid_to_pixelid[unique_id] = pixel_id\n", + "geo_object_mod0 = Geo(\"../larndsim/pixel_layouts/multi_tile_layout-2.3.16_mod0_swap_T8T4T7.yaml\")\n", + "geo_object_mod1 = Geo(\"../larndsim/pixel_layouts/multi_tile_layout-2.3.16_mod1_noswap.yaml\")\n", + "geo_object_mod3 = Geo(\"../larndsim/pixel_layouts/multi_tile_layout-2.3.16_mod3_swap_T5T8_T9T10.yaml\")\n", "\n", - "with open(\"pixelid_to_uniqueid_v2a.json\", \"w\") as f:\n", - " json.dump(pixelid_to_uniqueid, f)\n", - "with open(\"uniqueid_to_pixelid_v2a.json\", \"w\") as f:\n", - " json.dump(uniqueid_to_pixelid, f)\n" + "for i_mod, geo_object in zip([0,1,3], [geo_object_mod0, geo_object_mod1, geo_object_mod3]):\n", + " pixelid_to_uniqueid = dict()\n", + " uniqueid_to_pixelid = dict()\n", + "\n", + " for io_group in tqdm.tqdm(range(1, 3)):\n", + " for tile in range(1, 9):\n", + " for chip_id in range(11, 111):\n", + " for channel_id in range(64):\n", + " if io_group in [1, 2, 3, 4, 7, 8] and channel_id in nonrouted_v2a_channels:\n", + " continue\n", + " unique_id = ((io_group*10000+tile)*1000 + chip_id)*100 + channel_id\n", + " pixel_id = unique_id_to_pixel_id(unique_id, geo_object)\n", + " \n", + " if pixel_id in pixelid_to_uniqueid.keys():\n", + " print('DUPLICATE PIXEL ID')\n", + " print('pixel_id: ', pixel_id)\n", + " print('channel: ', (io_group, tile, chip_id, channel_id))\n", + " if channel_id in uniqueid_to_pixelid.keys():\n", + " print('DUPLICATE UNIQUE ID')\n", + " pixelid_to_uniqueid[pixel_id] = unique_id\n", + " uniqueid_to_pixelid[unique_id] = pixel_id\n", + " \n", + " with open(\"pixelid_to_uniqueid_mod{}.json\".format(i_mod), \"w\") as f:\n", + " json.dump(pixelid_to_uniqueid, f)\n", + " with open(\"uniqueid_to_pixelid_mod{}.json\".format(i_mod), \"w\") as f:\n", + " json.dump(uniqueid_to_pixelid, f)\n" ] }, { @@ -313,12 +243,15 @@ "pixelid_to_uniqueid = dict()\n", "uniqueid_to_pixelid = dict()\n", "\n", + "geo_object_mod2 = Geo(\"../larndsim/pixel_layouts/multi_tile_layout-2.5.16_mod2_swap_T7T8.yaml\")\n", + "\n", + "\n", "for io_group in tqdm.tqdm(range(1, 3)):\n", " for tile in range(1, 9):\n", " for chip_id in range(11, 111):\n", " for channel_id in range(64):\n", " unique_id = ((io_group*10000+tile)*1000 + chip_id)*100 + channel_id\n", - " pixel_id = unique_id_to_pixel_id(unique_id, is_mod2=True)\n", + " pixel_id = unique_id_to_pixel_id(unique_id, geo_object_mod2)\n", "\n", " if pixel_id in pixelid_to_uniqueid.keys():\n", " print('DUPLICATE PIXEL ID')\n", @@ -329,19 +262,11 @@ " pixelid_to_uniqueid[pixel_id] = unique_id\n", " uniqueid_to_pixelid[unique_id] = pixel_id\n", "\n", - "with open(\"pixelid_to_uniqueid_v2b.json\", \"w\") as f:\n", + "with open(\"pixelid_to_uniqueid_mod2.json\", \"w\") as f:\n", " json.dump(pixelid_to_uniqueid, f)\n", - "with open(\"uniqueid_to_pixelid_v2b.json\", \"w\") as f:\n", + "with open(\"uniqueid_to_pixelid_mod2.json\", \"w\") as f:\n", " json.dump(uniqueid_to_pixelid, f)\n" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d142c0c1-b6c0-42fe-962d-7d725336eb5f", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/examples/create_pedestals_file.ipynb b/examples/create_pedestals_file.ipynb index e2f10f30..e01f7779 100644 --- a/examples/create_pedestals_file.ipynb +++ b/examples/create_pedestals_file.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "99296be1-7d4b-4989-9648-f6cfeda72fb3", "metadata": {}, "outputs": [], @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "ef8ab2b2-60dd-4533-be2f-195c0b9e3db8", "metadata": {}, "outputs": [], @@ -28,19 +28,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "7b6865d8-ca8d-4c4f-a3e8-a70551c6fc71", "metadata": {}, "outputs": [], "source": [ - "with open('../../../run-ndlar-flow/ndlar_flow/data/proto_nd_flow/reference-cold-pedestal-2024_06_05_08_28_19_CDTevd_ped.tile_id_swapped.decimal.json', 'r') as f:\n", + "with open('/global/common/software/dune/mkramer/devel/flow4pedestal/reference-cold-pedestal-2024_06_05_08_28_19_CDTevd_ped.tile_id.decimal.json', 'r') as f:\n", " data = json.load(f)\n", " " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "037aad55-af7a-4976-ab16-2d893c142dfe", "metadata": {}, "outputs": [], @@ -67,7 +67,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "b22f7176-b65a-4756-893b-8e6c4d430cca", "metadata": {}, "outputs": [], @@ -87,165 +87,10 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "96d4e347-18fd-4108-aae3-79a83f090bd2", "metadata": {}, "outputs": [], - "source": [ - "with open('uniqueid_to_pixelid_v2a.json', 'r') as file:\n", - " unique_id_to_pixel_id_v2a = json.load(file)\n", - "with open('uniqueid_to_pixelid_v2b.json', 'r') as file:\n", - " unique_id_to_pixel_id_v2b = json.load(file)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2c1ddad8-9760-488b-a45a-114fef47042a", - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "np.unique(unique_to_channel_id(np.array(list(data.keys()), dtype=int)), return_counts=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ab838884-8b5e-4edc-9d16-8a5310cff6f8", - "metadata": {}, - "outputs": [], - "source": [ - "np.unique(unique_to_chip_id(np.array(list(data.keys()), dtype=int)), return_counts=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f01d41cf-b821-48e5-b8ed-720a43edada3", - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "np.unique(unique_to_io_channel(np.array(list(data.keys()), dtype=int)))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a7b8ea24-bb0e-4047-b162-647700184d6d", - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "np.unique(unique_to_io_channel(np.array(list(unique_id_to_pixel_id_v2a.keys()), dtype=int)))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "026544f0-780e-4d1e-9d21-f8afbbda60fe", - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "i = 0\n", - "pixel_ids = [[],[],[],[]] \n", - "pedestals = [[],[],[],[]]\n", - "nonrouted_v2a_channels = [6, 7, 8, 9, 22, 23, 24, 25, 38, 39, 40, 54, 55, 56, 57]\n", - "\n", - "\n", - "for k, v in data.items():\n", - " \n", - " \n", - " # unique_id = int(k)\n", - " pedestal = v['pedestal_mv']\n", - "\n", - " unique_id = int(k)\n", - "\n", - " unique_iog = unique_to_io_group(unique_id)\n", - " chip_id = unique_to_chip_id(unique_id)\n", - " converted_unique_id = convert_unique_id(unique_id)\n", - " channel_id = unique_to_channel_id(unique_id)\n", - " # tile_id = unique_to_io_channel(unique_id)\n", - " \n", - "\n", - " if chip_id not in range(11,111):\n", - " continue\n", - " \n", - " if (unique_iog in [1,2]) and (channel_id not in nonrouted_v2a_channels):\n", - " mod = 0\n", - " buff = 0\n", - " pixel_id = buff + unique_id_to_pixel_id_v2a[str(converted_unique_id)]\n", - " \n", - " elif (unique_iog in [3,4]) and (channel_id not in nonrouted_v2a_channels) :\n", - " mod = 1\n", - " buff = 7*10*2 * 7*10*4 * 2\n", - " pixel_id = buff + unique_id_to_pixel_id_v2a[str(converted_unique_id)]\n", - " \n", - " elif (unique_iog in [5,6]) :\n", - " mod = 2\n", - " buff = 8*10*2 * 8*10*4 * 2 * 2\n", - " pixel_id = buff + unique_id_to_pixel_id_v2b[str(converted_unique_id)]\n", - " \n", - " elif (unique_iog in [7,8]) and (channel_id not in nonrouted_v2a_channels):\n", - " mod = 3\n", - " buff = 7*10*2 * 7*10*4 * 2 * 3\n", - " pixel_id = buff + unique_id_to_pixel_id_v2a[str(converted_unique_id)]\n", - " \n", - " else:\n", - " continue\n", - " try:\n", - " pixel_ids[mod].append(pixel_id)\n", - " pedestals[mod].append(pedestal)\n", - " except:\n", - " break\n", - " \n", - " i+=1\n", - "\n", - "for i in range(4):\n", - " print(i)\n", - " out_file = 'pedestals_module{i}.npz'.format(i=i)\n", - " keys = np.array(pixel_ids[i], dtype='int64')\n", - " values = np.array(pedestals[i], dtype='float64')\n", - " default = np.array([580.])\n", - " np.savez(out_file, keys=keys, values=values, default=default)\n", - "# print(pixel_ids)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "28c86ef7-634a-40d4-a5cc-7a05622a2b10", - "metadata": {}, - "outputs": [], - "source": [ - "print( np.array(pixel_ids[0]).min(), np.array(pixel_ids[0]).max())\n", - "print( np.array(pixel_ids[1]).min(), np.array(pixel_ids[1]).max())\n", - "print( np.array(pixel_ids[2]).min(), np.array(pixel_ids[2]).max())\n", - "print( np.array(pixel_ids[3]).min(), np.array(pixel_ids[3]).max())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3d01b8d6-167d-428f-ac1a-b8dd908b0e9f", - "metadata": {}, - "outputs": [], - "source": [ - "#The below is using the json files Jaafar made me. The above uses files I generated through MapPixelIDToUniqueID_2x2.ipynb" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6949fa5f-e19c-4a6f-bed4-175f478a530b", - "metadata": {}, - "outputs": [], "source": [ "with open('uniqueid_to_pixelid_mod0.json', 'r') as file:\n", " unique_id_to_pixel_id_mod0 = json.load(file)\n", @@ -259,33 +104,23 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "63daa1c6-00ca-441e-8510-22559464449b", - "metadata": {}, - "outputs": [], - "source": [ - "with open('/global/common/software/dune/mkramer/devel/flow4pedestal/reference-cold-pedestal-2024_06_05_08_28_19_CDTevd_ped.tile_id.decimal.json', 'r') as f:\n", - " data = json.load(f)\n", - "\n", - "def convert_unique_id(unique_id):\n", - " io_group = (unique_to_io_group(unique_id) - 1) % 2 + 1\n", - " tile_id = (unique_to_io_channel(unique_id) - 1) % 8 + 1\n", - " chip_id = unique_to_chip_id(unique_id)\n", - " channel_id = unique_to_channel_id(unique_id)\n", - "\n", - " convert = (\n", - " (io_group*1000+tile_id)*1000 \\\n", - " + chip_id)*100 + channel_id\n", - " \n", - " return convert" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "83aa0332-dffa-4c5a-a4bb-2cf9a4919477", - "metadata": {}, - "outputs": [], + "execution_count": 7, + "id": "026544f0-780e-4d1e-9d21-f8afbbda60fe", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n" + ] + } + ], "source": [ "i = 0\n", "pixel_ids = [[],[],[],[]] \n", @@ -310,7 +145,6 @@ "\n", " if chip_id not in range(11,111):\n", " continue\n", - "\n", " \n", " if (unique_iog in [1,2]) and (channel_id not in nonrouted_v2a_channels):\n", " mod = 0\n", @@ -334,23 +168,17 @@ " \n", " else:\n", " continue\n", - " # print(k, unique_id)\n", " try:\n", " pixel_ids[mod].append(pixel_id)\n", " pedestals[mod].append(pedestal)\n", " except:\n", - " print(unique_id, converted_unique_id)\n", - " print(unique_iog, tile_id, chip_id, channel_id)\n", " break\n", " \n", - " # print(unique_id, pedestal, unique_iog)\n", - " # print(unique_id_to_pixel_id_v2a[k])\n", " i+=1\n", "\n", - "\n", "for i in range(4):\n", " print(i)\n", - " out_file = 'pedestals_module{i}_jaafars.npz'.format(i=i)\n", + " out_file = 'pedestals_module{i}.npz'.format(i=i)\n", " keys = np.array(pixel_ids[i], dtype='int64')\n", " values = np.array(pedestals[i], dtype='float64')\n", " default = np.array([580.])\n", @@ -360,10 +188,21 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "a7f40406-65f1-46af-8849-7efbba246ee5", + "execution_count": 8, + "id": "28c86ef7-634a-40d4-a5cc-7a05622a2b10", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 78399\n", + "78400 156799\n", + "204800 307199\n", + "235200 313599\n" + ] + } + ], "source": [ "print( np.array(pixel_ids[0]).min(), np.array(pixel_ids[0]).max())\n", "print( np.array(pixel_ids[1]).min(), np.array(pixel_ids[1]).max())\n", diff --git a/larndsim/config/config.yaml b/larndsim/config/config.yaml index 0ea49ed8..7323a7c9 100644 --- a/larndsim/config/config.yaml +++ b/larndsim/config/config.yaml @@ -41,8 +41,8 @@ module0: <<: *2x2main SIM_PROPERTIES: 2x2_NuMI_sim.yaml DET_PROPERTIES: 2x2.yaml - PIXEL_LAYOUT: [multi_tile_layout-2.4.16_v4.yaml, multi_tile_layout-2.5.16_v4.yaml] - PIXEL_LAYOUT_ID: [0, 0, 1, 0] + PIXEL_LAYOUT: [multi_tile_layout-2.3.16_mod0_swap_T8T4T7.yaml, multi_tile_layout-2.3.16_mod1_noswap.yaml, multi_tile_layout-2.5.16_mod2_swap_T7T8.yaml, multi_tile_layout-2.3.16_mod3_swap_T5T8_T9T10.yaml] + PIXEL_LAYOUT_ID: [0, 1, 2, 3] RESPONSE: [response_44_v2a_full.npz, response_38_v2b_full.npz] RESPONSE_ID: [0, 0, 1, 0] PIXEL_THRESHOLDS_FILE: [thresholds_module0.npz, thresholds_module1.npz, thresholds_module2.npz, thresholds_module3.npz] diff --git a/larndsim/detector_properties/2x2.yaml b/larndsim/detector_properties/2x2.yaml index 185f47e1..03a1c39c 100644 --- a/larndsim/detector_properties/2x2.yaml +++ b/larndsim/detector_properties/2x2.yaml @@ -17,8 +17,14 @@ tpc_offsets: # cm - [-33.5, 0., 33.5] - [-33.5, 0., -33.5] tile_map: + - [[8,5,3,1],[4,6,7,2]] + - [[16,14,12,10],[15,13,11,9]] - [[7,5,3,1],[8,6,4,2]] - [[16,14,12,10],[15,13,11,9]] + - [[8,5,3,1],[7,6,4,2]] + - [[16,14,12,10],[15,13,11,9]] + - [[7,8,3,1],[5,6,4,2]] + - [[16,14,12,9],[15,13,11,10]] module_to_io_groups: 1: [1, 2] 2: [3, 4] diff --git a/larndsim/fee.py b/larndsim/fee.py index 095769bb..4a23fb1e 100644 --- a/larndsim/fee.py +++ b/larndsim/fee.py @@ -168,8 +168,7 @@ def export_to_hdf5(event_id_list, tile_x = int(pix_x//detector.N_PIXELS_PER_TILE[0]) tile_y = int(pix_y//detector.N_PIXELS_PER_TILE[1]) - anode_id = 0 if plane_id % 2 == 0 else 1 - tile_id = detector.TILE_MAP[anode_id][tile_x][tile_y] + tile_id = detector.TILE_MAP[plane_id][tile_x][tile_y] for iadc, adc in enumerate(adcs): t = ts[iadc]