Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:45

0001 # ==========================================================================
0002 #  AIDA Detector description implementation
0003 # --------------------------------------------------------------------------
0004 # Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 # All rights reserved.
0006 #
0007 # For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 # For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 #
0010 # ==========================================================================
0011 """
0012    dd4hep example setup using the python configuration
0013 
0014    \author  M.Frank
0015    \version 1.0
0016 
0017 """
0018 from __future__ import absolute_import, unicode_literals
0019 import logging
0020 import math
0021 import time
0022 import sys
0023 import os
0024 from g4units import rad, GeV, MeV, mm, m
0025 
0026 
0027 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0028 logger = logging.getLogger(__name__)
0029 
0030 
0031 def show_help():
0032   logging.info("Check_shape.py -option [-option]                           ")
0033   logging.info("       -geometry   <geometry file>   Geometry file         ")
0034   logging.info("       -vis                          Enable visualization  ")
0035   logging.info("       -batch                        Batch execution       ")
0036 
0037 
0038 def run():
0039   geo = None
0040   vis = False
0041   dump = False
0042   batch = False
0043   install_dir = os.environ['DD4hepINSTALL']
0044   #
0045   for i in list(range(len(sys.argv))):
0046     c = sys.argv[i].upper()
0047     if c.find('BATCH') < 2 and c.find('BATCH') >= 0:
0048       batch = True
0049     elif c[:4] == '-GEO':
0050       geo = sys.argv[i + 1]
0051     elif c[:4] == '-VIS':
0052       vis = True
0053     elif c[:4] == '-DUM':
0054       dump = True
0055 
0056   if not geo:
0057     show_help()
0058     sys.exit(1)
0059 
0060   import DDG4
0061   kernel = DDG4.Kernel()
0062   description = kernel.detectorDescription()
0063   DDG4.setPrintLevel(DDG4.OutputLevel.INFO)
0064   DDG4.importConstants(description)
0065   #
0066   # Configure UI
0067   geant4 = DDG4.Geant4(kernel)
0068   ui = None
0069   if batch:
0070     geant4.setupCshUI(ui=None, vis=None)
0071     kernel.UI = 'UI'
0072   else:
0073     ui = geant4.setupCshUI(vis=vis)
0074   Output = DDG4.OutputLevel
0075 
0076   seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0077   act.DebugReflections = True
0078   act.DebugMaterials = False
0079   act.DebugElements = False
0080   act.DebugVolumes = False
0081   act.DebugShapes = False
0082   if dump:
0083     act.DumpHierarchy = ~0x0
0084   #
0085   kernel.setOutputLevel(str('Geant4Converter'), Output.WARNING)
0086   kernel.loadGeometry(geo)
0087   #
0088   geant4.printDetectors()
0089   # Configure field
0090   geant4.setupTrackingField(prt=True)
0091   logger.info("#  Setup random generator")
0092   rndm = DDG4.Action(kernel, 'Geant4Random/Random')
0093   rndm.Seed = 987654321
0094   rndm.initialize()
0095   #
0096   # Setup detector
0097   seq, act = geant4.setupCalorimeter('NestedBox')
0098   #
0099   # Configure I/O
0100   geant4.setupROOTOutput('RootOutput', 'Reflections_' + time.strftime('%Y-%m-%d_%H-%M'), mc_truth=True)
0101   #
0102   # Setup particle gun
0103   geant4.setupGun(name="Gun",
0104                   particle='e-',
0105                   energy=1000 * GeV,
0106                   isotrop=True,
0107                   multiplicity=1,
0108                   position=(0 * m, 0 * m, 0 * m),
0109                   PhiMin=0.0 * rad,
0110                   PhiMax=math.pi * 2.0 * rad,
0111                   ThetaMin=0.0 * rad,
0112                   ThetaMax=math.pi * rad)
0113 
0114   logger.info("#  ....and handle the simulation particles.")
0115   part = DDG4.GeneratorAction(kernel, str('Geant4ParticleHandler/ParticleHandler'))
0116   kernel.generatorAction().adopt(part)
0117   part.MinimalKineticEnergy = 100 * MeV
0118   part.SaveProcesses = ['Decay']
0119   part.OutputLevel = 5  # generator_output_level
0120   part.enableUI()
0121   user = DDG4.Action(kernel, str('Geant4TCUserParticleHandler/UserParticleHandler'))
0122   user.TrackingVolume_Rmax = 3.0 * m
0123   user.TrackingVolume_Zmax = 2.0 * m
0124   user.enableUI()
0125   part.adopt(user)
0126   #
0127   #
0128   prt = DDG4.EventAction(kernel, str('Geant4ParticlePrint/ParticlePrint'))
0129   prt.OutputLevel = Output.INFO
0130   prt.OutputType = 3  # Print both: table and tree
0131   kernel.eventAction().adopt(prt)
0132   #
0133   # Now build the physics list:
0134   phys = geant4.setupPhysics(str('QGSP_BERT'))
0135   ph = geant4.addPhysics(str('Geant4PhysicsList/Myphysics'))
0136   ph.addPhysicsConstructor(str('G4StepLimiterPhysics'))
0137   ph.addParticleConstructor(str('G4Geantino'))
0138   ph.addParticleConstructor(str('G4BosonConstructor'))
0139   #
0140   # Add special particle types from specialized physics constructor
0141   part = geant4.addPhysics('Geant4ExtraParticles/ExtraParticles')
0142   part.pdgfile = os.path.join(install_dir, 'examples/DDG4/examples/particle.tbl')
0143   #
0144   # Add global range cut
0145   rg = geant4.addPhysics('Geant4DefaultRangeCut/GlobalRangeCut')
0146   rg.RangeCut = 0.7 * mm
0147   #
0148   phys.dump()
0149   #
0150   #
0151   if ui and vis:
0152     cmds = []
0153     cmds.append('/control/verbose 2')
0154     cmds.append('/run/initialize')
0155     cmds.append('/vis/open OGL')
0156     cmds.append('/vis/verbose errors')
0157     cmds.append('/vis/drawVolume')
0158     cmds.append('/vis/viewer/set/viewpointThetaPhi 55. 45.')
0159     cmds.append('/vis/scene/add/axes 0 0 0 3 m')
0160     ui.Commands = cmds
0161   kernel.NumEvents = 0
0162   kernel.configure()
0163   kernel.initialize()
0164   kernel.run()
0165   kernel.terminate()
0166 
0167 
0168 if __name__ == "__main__":
0169   run()