Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
odd.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file odd.py
1 from pathlib import Path
2 from math import sqrt
3 import sys, os
4 import acts
5 import acts.examples
6 
7 
9  odd_dir: Path,
10  mdecorator=None,
11  logLevel=acts.logging.INFO,
12 ):
13 
15 
16  customLogLevel = acts.examples.defaultLogging(logLevel=logLevel)
17 
18  odd_xml = odd_dir / "xml" / "OpenDataDetector.xml"
19  if not odd_xml.exists():
20  raise RuntimeError(f"OpenDataDetector.xml not found at {odd_xml}")
21 
22  env_vars = []
23  map_name = "libOpenDataDetector.components"
24  lib_name = None
25  if sys.platform == "linux":
26  env_vars = ["LD_LIBRARY_PATH"]
27  lib_name = "libOpenDataDetector.so"
28  elif sys.platform == "darwin":
29  env_vars = ["DYLD_LIBRARY_PATH", "DD4HEP_LIBRARY_PATH"]
30  lib_name = "libOpenDataDetector.dylib"
31 
32  if lib_name is not None and len(env_vars) > 0:
33  found = False
34  for env_var in env_vars:
35  for lib_dir in os.environ.get(env_var, "").split(":"):
36  lib_dir = Path(lib_dir)
37  if (lib_dir / map_name).exists() and (lib_dir / lib_name).exists():
38  found = True
39  break
40  if not found:
41  msg = (
42  "Unable to find OpenDataDetector factory library. "
43  f"You might need to point {'/'.join(env_vars)} to build/thirdparty/OpenDataDetector/factory or other ODD install location"
44  )
45  raise RuntimeError(msg)
46 
47  volumeRadiusCutsMap = {
48  28: [850.0], # LStrip negative z
49  30: [850.0], # LStrip positive z
50  23: [400.0, 550.0], # SStrip negative z
51  25: [400.0, 550.0], # SStrip positive z
52  16: [100.0], # Pixels negative z
53  18: [100.0], # Pixels positive z
54  }
55 
56  def geoid_hook(geoid, surface):
57  if geoid.volume() in volumeRadiusCutsMap:
58  r = sqrt(surface.center()[0] ** 2 + surface.center()[1] ** 2)
59 
60  geoid.setExtra(1)
61  for cut in volumeRadiusCutsMap[geoid.volume()]:
62  if r > cut:
63  geoid.setExtra(geoid.extra() + 1)
64 
65  return geoid
66 
67  dd4hepConfig = acts.examples.dd4hep.DD4hepGeometryService.Config(
68  xmlFileNames=[str(odd_xml)],
69  logLevel=customLogLevel(),
70  dd4hepLogLevel=customLogLevel(),
71  geometryIdentifierHook=acts.GeometryIdentifierHook(geoid_hook),
72  )
73  detector = acts.examples.dd4hep.DD4hepDetector()
74 
75  config = acts.MaterialMapJsonConverter.Config()
76  if mdecorator is None:
77  mdecorator = acts.JsonMaterialDecorator(
78  rConfig=config,
79  jFileName=str(odd_dir / "config/odd-material-mapping-config.json"),
80  level=customLogLevel(minLevel=acts.logging.WARNING),
81  )
82 
83  trackingGeometry, deco = detector.finalize(dd4hepConfig, mdecorator)
84 
85  return detector, trackingGeometry, deco