3 from pathlib
import Path
10 CsvTrackingGeometryWriter,
11 ObjTrackingGeometryWriter,
19 from acts
import MaterialMapJsonConverter, UnitConstants
as u
32 for ievt
in range(events):
33 eventStore = WhiteBoard(name=f
"EventStore#{ievt}", level=acts.logging.INFO)
36 context = AlgorithmContext(ialg, ievt, eventStore)
38 for cdr
in decorators:
39 r = cdr.decorate(context)
40 if r != ProcessCode.SUCCESS:
41 raise RuntimeError(
"Failed to decorate event context")
44 csv_dir = outputDir /
"csv"
45 csv_dir.mkdir(exist_ok=
True)
46 writer = CsvTrackingGeometryWriter(
47 level=acts.logging.INFO,
48 trackingGeometry=trackingGeometry,
49 outputDir=
str(csv_dir),
55 obj_dir = outputDir /
"obj"
56 obj_dir.mkdir(exist_ok=
True)
57 writer = ObjTrackingGeometryWriter(
58 level=acts.logging.INFO,
59 outputDir=
str(obj_dir),
61 writer.write(context, trackingGeometry)
64 json_dir = outputDir /
"json"
65 json_dir.mkdir(exist_ok=
True)
66 writer = JsonSurfacesWriter(
67 level=acts.logging.INFO,
68 trackingGeometry=trackingGeometry,
69 outputDir=
str(json_dir),
75 jmConverterCfg = MaterialMapJsonConverter.Config(
76 processSensitives=
True,
77 processApproaches=
True,
78 processRepresenting=
True,
79 processBoundaries=
True,
81 processNonMaterial=
True,
82 context=context.geoContext,
85 jmw = JsonMaterialWriter(
86 level=acts.logging.VERBOSE,
87 converterCfg=jmConverterCfg,
88 fileName=
str(json_dir /
"material-map"),
89 writeFormat=JsonFormat.Json,
92 jmw.write(trackingGeometry)
95 if "__main__" == __name__:
96 p = argparse.ArgumentParser(
97 description=
"Example script to construct the ITk geometry and write it out to CSV and OBJ formats"
101 help=
"Input directory containing the ITk standalone geometry. Get in touch if you don't have this.",
107 help=
"Directory to write outputs to",
110 "--output-csv", action=
"store_true", help=
"Write geometry in CSV format."
113 "--output-obj", action=
"store_true", help=
"Write geometry in OBJ format."
118 help=
"Write geometry and material in JSON format.",
121 "--no-material", action=
"store_true", help=
"Decorate material to the geometry"
124 args = p.parse_args()
125 args.output_dir.mkdir(exist_ok=
True, parents=
True)
127 geo_example_dir = Path(args.geo_dir)
128 assert geo_example_dir.exists(),
"Detector example input directory missing"
133 material=
not args.no_material,
137 trackingGeometry=trackingGeometry,
138 decorators=decorators,
139 outputDir=args.output_dir,
140 outputCsv=args.output_csv,
141 outputObj=args.output_obj,
142 outputJson=args.output_json,