Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
geometry.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file geometry.py
1 #!/usr/bin/env python3
2 import os
3 from common import getOpenDataDetectorDirectory
4 from acts.examples.odd import getOpenDataDetector
5 from acts.examples import (
6  GenericDetector,
7  AlignedDetector,
8  WhiteBoard,
9  AlgorithmContext,
10  ProcessCode,
11  CsvTrackingGeometryWriter,
12  ObjTrackingGeometryWriter,
13  JsonSurfacesWriter,
14  JsonMaterialWriter,
15  JsonFormat,
16 )
17 
18 import acts
19 
20 from acts import MaterialMapJsonConverter
21 
22 
23 def runGeometry(
24  trackingGeometry,
25  decorators,
26  outputDir,
27  events=1,
28  outputObj=True,
29  outputCsv=True,
30  outputJson=True,
31  outputRoot=True,
32 ):
33 
34  for ievt in range(events):
35  eventStore = WhiteBoard(name=f"EventStore#{ievt}", level=acts.logging.INFO)
36  ialg = 0
37 
38  context = AlgorithmContext(ialg, ievt, eventStore)
39 
40  for cdr in decorators:
41  r = cdr.decorate(context)
42  if r != ProcessCode.SUCCESS:
43  raise RuntimeError("Failed to decorate event context")
44 
45  if outputCsv:
46  writer = CsvTrackingGeometryWriter(
47  level=acts.logging.INFO,
48  trackingGeometry=trackingGeometry,
49  outputDir=os.path.join(outputDir, "csv"),
50  writePerEvent=True,
51  )
52  writer.write(context)
53 
54  if outputObj:
55  writer = ObjTrackingGeometryWriter(
56  level=acts.logging.INFO, outputDir=os.path.join(outputDir, "obj")
57  )
58  writer.write(context, trackingGeometry)
59 
60  if outputJson:
61  writer = JsonSurfacesWriter(
62  level=acts.logging.INFO,
63  trackingGeometry=trackingGeometry,
64  outputDir=os.path.join(outputDir, "json"),
65  writePerEvent=True,
66  writeSensitive=True,
67  )
68  writer.write(context)
69 
70  jmConverterCfg = MaterialMapJsonConverter.Config(
71  processSensitives=True,
72  processApproaches=True,
73  processRepresenting=True,
74  processBoundaries=True,
75  processVolumes=True,
76  processNonMaterial=True,
77  context=context.geoContext,
78  )
79 
80  jmw = JsonMaterialWriter(
81  level=acts.logging.VERBOSE,
82  converterCfg=jmConverterCfg,
83  fileName=os.path.join(outputDir, "geometry-map"),
84  writeFormat=JsonFormat.Json,
85  )
86 
87  jmw.write(trackingGeometry)
88 
89 
90 if "__main__" == __name__:
91  detector, trackingGeometry, decorators = AlignedDetector.create()
92  # detector, trackingGeometry, decorators = GenericDetector.create()
93  # detector, trackingGeometry, decorators = getOpenDataDetector(getOpenDataDetectorDirectory())
94 
95  runGeometry(trackingGeometry, decorators, outputDir=os.getcwd())