File indexing completed on 2025-01-18 09:12:08
0001
0002 import argparse
0003
0004 from pathlib import Path
0005
0006 import acts
0007 import acts.examples
0008 from acts.examples.simulation import addParticleGun, addGeant4, EtaConfig
0009 from acts.examples.odd import getOpenDataDetector, getOpenDataDetectorDirectory
0010
0011 u = acts.UnitConstants
0012
0013
0014 def runGeant4(
0015 detector,
0016 trackingGeometry,
0017 field,
0018 outputDir,
0019 materialMappings=["Silicon"],
0020 volumeMappings=[],
0021 s: acts.examples.Sequencer = None,
0022 ):
0023 s = s or acts.examples.Sequencer(events=100, numThreads=1)
0024 s.config.logLevel = acts.logging.INFO
0025 rnd = acts.examples.RandomNumbers()
0026 addParticleGun(
0027 s,
0028 EtaConfig(-2.0, 2.0),
0029 rnd=rnd,
0030 )
0031 outputDir = Path(outputDir)
0032 addGeant4(
0033 s,
0034 detector,
0035 trackingGeometry,
0036 field,
0037 outputDirCsv=outputDir / "csv",
0038 outputDirRoot=outputDir,
0039 outputDirObj=outputDir / "obj",
0040 rnd=rnd,
0041 materialMappings=materialMappings,
0042 volumeMappings=volumeMappings,
0043 )
0044 return s
0045
0046
0047 if "__main__" == __name__:
0048 p = argparse.ArgumentParser()
0049
0050 p.add_argument(
0051 "--experimental",
0052 action=argparse.BooleanOptionalAction,
0053 help="Construct experimental geometry",
0054 )
0055
0056 args = p.parse_args()
0057
0058 field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
0059
0060 if args.experimental:
0061 from acts.examples.dd4hep import (
0062 DD4hepDetector,
0063 DD4hepDetectorOptions,
0064 DD4hepGeometryService,
0065 )
0066
0067 print(">>> Running experimental geometry <<<")
0068 odd_xml = getOpenDataDetectorDirectory() / "xml" / "OpenDataDetector.xml"
0069
0070
0071 dd4hepConfig = DD4hepGeometryService.Config()
0072 dd4hepConfig.logLevel = acts.logging.INFO
0073 dd4hepConfig.xmlFileNames = [str(odd_xml)]
0074 dd4hepGeometryService = DD4hepGeometryService(dd4hepConfig)
0075 dd4hepDetector = DD4hepDetector(dd4hepGeometryService)
0076
0077 cOptions = DD4hepDetectorOptions(logLevel=acts.logging.INFO, emulateToGraph="")
0078
0079
0080 geoContext = acts.GeometryContext()
0081 [detector, contextors, store] = dd4hepDetector.finalize(geoContext, cOptions)
0082 runGeant4(detector, detector, field, Path.cwd()).run()
0083 else:
0084 detector = getOpenDataDetector()
0085 trackingGeometry = detector.trackingGeometry()
0086 decorators = detector.contextDecorators()
0087 runGeant4(detector, trackingGeometry, field, Path.cwd()).run()