From 86f0500999a7f69d9f47da750dcccba74a8c174e Mon Sep 17 00:00:00 2001 From: Wouter Deconinck <wouter.deconinck@umanitoba.ca> Date: Fri, 4 Jun 2021 14:34:01 +0000 Subject: [PATCH] Feature: Convert to GDML script and pipeline integration --- .gitlab-ci.yml | 9 ++++++++ scripts/convert_to_gdml.py | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 scripts/convert_to_gdml.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 65874fc8..a9d600dd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -124,6 +124,7 @@ report: - view_15 - dump_constants - dump_geometry + - convert_to_gdml script: - pip3 install jinja2 && ls -lrth - ./bin/make_images > doc/dawn_views.md @@ -144,6 +145,14 @@ overlap_check: - echo "$(cat doc/overlap_check.out | grep ovlp | wc -l) overlaps..." - if [[ "$(cat doc/overlap_check.out | grep ovlp | wc -l)" -gt "0" ]] ; then echo "Overlaps exist!" && false ; fi +convert_to_gdml: + stage: test + needs: + - ["common:detector"] + script: + - mkdir -p geo + - python scripts/convert_to_gdml.py --compact ${DETECTOR_PATH}/athena.xml --output geo/athena.gdml + tracking_geometry_debug: stage: test allow_failure: true diff --git a/scripts/convert_to_gdml.py b/scripts/convert_to_gdml.py new file mode 100755 index 00000000..ce00df35 --- /dev/null +++ b/scripts/convert_to_gdml.py @@ -0,0 +1,47 @@ +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("--compact", help="compact detector file",default="athena.xml") +parser.add_argument("--output", help="gdml detector file",default="athena.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/write' + ] + kernel.configure() + kernel.initialize() + kernel.run() + kernel.terminate() + + +if __name__ == "__main__": + run() -- GitLab