Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-24 07:37:00

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