Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 08:59:27

0001 #!/usr/bin/env python
0002 # produce auxiliary ROOT file for the IRT algorithm; assumes the
0003 # production of `libIRT` objects is in the geometry `cpp` file
0004 # 
0005 # DEPRECATED for usage in EPIC; this script is preserved for 2 reasons:
0006 # 1. usage for ATHENA support
0007 # 2. example how to edit compact files on-the-fly with Python
0008 
0009 import shutil, os, sys, argparse
0010 import xml.etree.ElementTree as et
0011 
0012 # arguments
0013 parser = argparse.ArgumentParser()
0014 parser.add_argument(
0015         '-o', '--output-name', dest='outFile', required=True,
0016         help='output auxiliary ROOT file name', type=str
0017         )
0018 argv = parser.parse_args()
0019 
0020 # import DDG4 after arg-parsing; it is slower
0021 import DDG4
0022 
0023 ########################################
0024 
0025 # compact files
0026 if not 'DETECTOR_PATH' in os.environ:
0027     print('ERROR: env var DETECTOR_PATH not set',file=sys.stderr)
0028     exit(1)
0029 mainFile = os.environ['DETECTOR_PATH'] + '/' + os.environ['DETECTOR'] + '.xml'
0030 richFile = os.environ['DETECTOR_PATH'] + '/compact/drich.xml'
0031 
0032 ########################################
0033 
0034 # backup original richFile, then parse
0035 shutil.copy(richFile,richFile+'.bak')
0036 richTree = et.parse(richFile)
0037 
0038 # enable `DRICH_create_irt_file` mode
0039 for constant in richTree.iter(tag='constant'):
0040     if(constant.attrib['name']=='DRICH_create_irt_file'):
0041         constant.set('value','1')
0042 
0043 # set auxiliary file name
0044 for detector in richTree.iter(tag='detector'):
0045     detector.set('irt_filename',argv.outFile)
0046 
0047 # overwrite original richFile
0048 richTree.write(richFile)
0049 
0050 ########################################
0051 
0052 # produce IRT config file
0053 try:
0054     kernel = DDG4.Kernel()
0055     kernel.loadGeometry(f'file:{mainFile}')
0056     kernel.terminate()
0057     print(f'\n -> produced {argv.outFile}\n')
0058 except:
0059     pass
0060 
0061 # revert to the original richFile
0062 os.replace(richFile+'.bak',richFile)