Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:32:28

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