-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_to_gdml.py
executable file
·52 lines (43 loc) · 1.42 KB
/
convert_to_gdml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2022 Wouter Deconinck
from __future__ import absolute_import, unicode_literals
import os
import time
import logging
import argparse
parser = argparse.ArgumentParser(
prog='convert_to_gdml.py',
description='''Convert DD4Hep description to GDML''',
epilog='''
This program converts the compact detector file to a single GDML file.
''')
parser.add_argument("-c", "--compact", help="compact detector file",default=f'{os.getenv("DETECTOR_PATH")}/{os.getenv("DETECTOR")}.xml')
parser.add_argument("-o", "--output", help="gdml detector file",default=f'{os.getenv("DETECTOR")}.gdml')
args = parser.parse_args()
import DDG4
from g4units import keV, GeV, mm, ns, MeV
def run():
kernel = DDG4.Kernel()
description = kernel.detectorDescription()
kernel.loadGeometry(str("file:" + args.compact))
DDG4.importConstants(description)
geant4 = DDG4.Geant4(kernel)
ui = geant4.setupCshUI(ui=None)
#
# Setup the GDML writer action
writer = DDG4.Action(kernel, 'Geant4GDMLWriteAction/Writer')
writer.enableUI()
kernel.registerGlobalAction(writer)
ui.Commands = [
'/ddg4/Writer/Output {}'.format(args.output),
'/ddg4/Writer/OverWrite 1',
'/ddg4/Writer/ModuleDepth 1',
'/ddg4/Writer/write'
]
kernel.configure()
kernel.initialize()
kernel.run()
kernel.terminate()
if __name__ == "__main__":
run()