Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:22

0001 #!/usr/bin/env python
0002 # ==========================================================================
0003 #  AIDA Detector description implementation
0004 # --------------------------------------------------------------------------
0005 # Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0006 # All rights reserved.
0007 #
0008 # For the licensing terms see $DD4hepINSTALL/LICENSE.
0009 # For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0010 #
0011 # ==========================================================================
0012 
0013 from __future__ import absolute_import, unicode_literals
0014 import os
0015 import sys
0016 import errno
0017 import optparse
0018 import logging
0019 
0020 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0021 logger = logging.getLogger(__name__)
0022 
0023 
0024 def printOpts(opts):
0025   o = eval(str(opts))
0026   prefix = sys.argv[0].split(os.sep)[-1]
0027   for name, value in o.items():
0028     logger.info('%s > %-18s %s  [%s]', prefix, name + ':', str(value), str(value.__class__))
0029 
0030 
0031 def materialScan(opts):
0032   kernel = DDG4.Kernel()
0033   kernel.loadGeometry(str(opts.compact))
0034   DDG4.Core.setPrintFormat(str("%-32s %6s %s"))
0035   geant4 = DDG4.Geant4(kernel)
0036   # Configure UI
0037   geant4.setupCshUI(ui=None)
0038   for i in geant4.description.detectors():
0039     o = DDG4.DetElement(i.second.ptr())
0040     sd = geant4.description.sensitiveDetector(o.name())
0041     if sd.isValid():
0042       typ = sd.type()
0043       if typ in geant4.sensitive_types:
0044         geant4.setupDetector(o.name(), geant4.sensitive_types[typ])
0045       else:
0046         logger.error('+++  %-32s type:%-12s  --> Unknown Sensitive type: %s', o.name(), typ, typ)
0047         sys.exit(errno.EINVAL)
0048 
0049   geant4.setupGun("Gun",
0050                   Standalone=True,
0051                   particle='geantino',
0052                   energy=20 * g4units.GeV,
0053                   position=opts.position,
0054                   direction=opts.direction,
0055                   multiplicity=1,
0056                   isotrop=False)
0057   scan = DDG4.SteppingAction(kernel, 'Geant4GeometryScanner/GeometryScan')
0058   kernel.steppingAction().adopt(scan)
0059 
0060   # Now build the physics list:
0061   geant4.setupPhysics('QGSP_BERT')
0062 
0063   kernel.configure()
0064   kernel.initialize()
0065   kernel.NumEvents = 1
0066   kernel.run()
0067   kernel.terminate()
0068   return 0
0069 
0070 
0071 parser = optparse.OptionParser()
0072 parser.formatter.width = 132
0073 parser.description = 'Scan Volumes along a trajectory using Geant4.'
0074 parser.add_option('-c', '--compact', dest='compact', default=None,
0075                   help='Define LCCDD style compact xml input',
0076                   metavar='<FILE>')
0077 parser.add_option('-P', '--print',
0078                   dest='print_level', default=2,
0079                   help='Set dd4hep print level.',
0080                   metavar='<int>')
0081 parser.add_option('-p', '--position',
0082                   dest='position', default='0.0,0.0,0.0',
0083                   help='Start position of the material scan. [give tuple "x,y,z" as string]',
0084                   metavar='<tuple>')
0085 parser.add_option('-d', '--direction',
0086                   dest='direction', default='0.0,1.0,0.0',
0087                   help='Direction of the material scan. [give tuple "x,y,z" as string]',
0088                   metavar='<tuple>')
0089 
0090 (opts, args) = parser.parse_args()
0091 
0092 if opts.compact is None:
0093   logger.info("%s", parser.format_help())
0094   sys.exit(1)
0095 
0096 opts.position = eval('(' + opts.position + ')')
0097 opts.direction = eval('(' + opts.direction + ')')
0098 printOpts(opts)
0099 
0100 try:
0101   from ROOT import gROOT
0102   gROOT.SetBatch(1)
0103 except ImportError as X:
0104   logger.error('PyROOT interface not accessible: %s', X)
0105   logger.info(parser.format_help())
0106   sys.exit(errno.ENOENT)
0107 
0108 try:
0109   import DDG4
0110   import g4units
0111 except ImportError as X:
0112   logger.error('DDG4 python interface not accessible: %s', X)
0113   logger.info(parser.format_help())
0114   sys.exit(errno.ENOENT)
0115 #
0116 ret = materialScan(opts)
0117 sys.exit(ret)