Skip to content
Draft
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
305 changes: 115 additions & 190 deletions examples/MapPixelIDToUniqueID_2x2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
]
},
{
Expand All @@ -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",
Expand All @@ -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"
]
},
{
Expand All @@ -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",
Expand All @@ -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": {
Expand Down
Loading