File indexing completed on 2026-09-05 08:18:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 from options import (
0011 common_options,
0012 detector_io_options,
0013 display_options,
0014 )
0015 from options import (
0016 parse_common_options,
0017 parse_detector_io_options,
0018 parse_display_options,
0019 fill_reader_config,
0020 )
0021
0022
0023 import detray.core
0024 import detray.io
0025 import detray.svgtools
0026
0027
0028 import argparse
0029 import os
0030
0031
0032 def run_detector_display(args, outdir):
0033
0034
0035 reader_cfg = fill_reader_config(args, detray.io.DetectorReaderConfig())
0036 reader_cfg.doCheck = False
0037 det, names = detray.io.readDetector(detray.core.HostMemoryResource(), reader_cfg)
0038
0039
0040 style = detray.svgtools.tableauColorblindStyle()
0041 style.fontSize = args.font_size
0042
0043 style.materialGradientPos = [args.material_gradient_axis + 100.0, -200.0]
0044
0045
0046 il = detray.svgtools.Illustrator(det, names, style)
0047 il.showInfo(args.show_info)
0048 il.hideEtaLines(args.hide_eta_lines)
0049 il.hidePortals(args.hide_portals)
0050 il.hidePassives(args.hide_passives)
0051 il.hideMaterial(not args.material_file or args.hide_material)
0052 il.hideGrids(not args.grid_file)
0053 il.searchWindow(args.search_window)
0054
0055
0056 gctx = detray.core.GeometryContext(args.context)
0057
0058
0059 xy_axis = detray.svgtools.drawAxes(
0060 "axes",
0061 [-args.x_axis, args.x_axis],
0062 [-args.y_axis, args.y_axis],
0063 "x",
0064 "y",
0065 args.font_size,
0066 )
0067 zr_axis = detray.svgtools.drawAxes(
0068 "axes",
0069 [-args.z_axis, args.z_axis],
0070 [-5.0, args.r_axis],
0071 "z",
0072 "r",
0073 args.font_size,
0074 )
0075 zphi_axis = detray.svgtools.drawAxes(
0076 "axes",
0077 [-args.z_axis, args.z_axis],
0078 [-args.r_axis, args.r_axis],
0079 "z",
0080 "phi",
0081 args.font_size,
0082 )
0083
0084
0085 xy = detray.svgtools.ViewXY()
0086 zr = detray.svgtools.ViewZR()
0087 zphi = detray.svgtools.ViewZPhi()
0088 zrphi = detray.svgtools.ViewZRPhi()
0089
0090 def write_svg(name, svgs):
0091 detray.svgtools.writeSvg(os.path.join(outdir, name), svgs)
0092
0093
0094 def draw_volumes(vol_ids):
0095 vol_xy_svg, xy_grids = il.drawVolumes(vol_ids, xy, gctx)
0096 write_svg(vol_xy_svg.id, [xy_axis, vol_xy_svg])
0097 for grid in xy_grids:
0098 write_svg(grid.id, [grid])
0099
0100 vol_zr_svg, _ = il.drawVolumes(vol_ids, zr, gctx)
0101 write_svg(vol_zr_svg.id, [zr_axis, vol_zr_svg])
0102
0103 _, zrphi_grids = il.drawVolumes(vol_ids, zrphi, gctx)
0104 for grid in zrphi_grids:
0105 write_svg(grid.id, [grid])
0106
0107
0108 if args.volume_indices:
0109 draw_volumes(args.volume_indices)
0110 if args.volume_names:
0111 draw_volumes(args.volume_names)
0112
0113
0114 if args.surfaces:
0115 sf_xy_svg, mat_xy_svg = il.drawSurfaces(args.surfaces, xy, gctx)
0116 write_svg(sf_xy_svg.id, [xy_axis, sf_xy_svg])
0117 write_svg(mat_xy_svg.id, [xy_axis, mat_xy_svg])
0118
0119 sf_zr_svg, _ = il.drawSurfaces(args.surfaces, zr, gctx)
0120 write_svg(sf_zr_svg.id, [zr_axis, sf_zr_svg])
0121
0122 _, mat_zphi_svg = il.drawSurfaces(args.surfaces, zphi, gctx)
0123 write_svg(mat_zphi_svg.id, [zphi_axis, mat_zphi_svg])
0124
0125
0126 if not args.volume_indices and not args.volume_names and not args.surfaces:
0127 det_xy_svg = il.drawDetector(xy, gctx)
0128 write_svg(det_xy_svg.id, [xy_axis, det_xy_svg])
0129
0130 det_zr_svg = il.drawDetector(zr, gctx, args.r_axis, args.z_axis)
0131 write_svg(det_zr_svg.id, [zr_axis, det_zr_svg])
0132
0133
0134 if args.write_volume_graph:
0135 graph = detray.core.VolumeGraph(det)
0136
0137 graph_file = os.path.join(outdir, il.detName + "_volume_graph.dot")
0138 with open(graph_file, "w") as out_file:
0139 out_file.write(graph.toDotString())
0140
0141
0142 def __main__():
0143
0144
0145
0146 descr = "Detray Detector Display"
0147
0148
0149 parent_parsers = [
0150 common_options(descr),
0151 detector_io_options(),
0152 display_options(),
0153 ]
0154
0155 parser = argparse.ArgumentParser(description=descr, parents=parent_parsers)
0156
0157 args = parser.parse_args()
0158
0159 logging = parse_common_options(args, descr)
0160 parse_detector_io_options(args, logging)
0161 outdir = parse_display_options(args, logging)
0162
0163
0164
0165 logging.debug("Drawing the detector")
0166 run_detector_display(args, outdir)
0167
0168 logging.info(f"Wrote the svg files to '{outdir}'")
0169
0170
0171
0172
0173 if __name__ == "__main__":
0174 __main__()
0175
0176