Back to home page

EIC code displayed by LXR

 
 

    


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

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 #
0013 from __future__ import absolute_import, unicode_literals
0014 import logging
0015 #
0016 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0017 logger = logging.getLogger(__name__)
0018 #
0019 #
0020 """
0021 
0022    dd4hep simulation example setup using the python configuration
0023 
0024    @author  M.Frank
0025    @version 1.0
0026 
0027 """
0028 
0029 
0030 def run():
0031   import os
0032   import sys
0033   import time
0034   import DDG4
0035   args = DDG4.CommandLine()
0036   install_dir = os.environ['DD4hepExamplesINSTALL']
0037   install_dir = install_dir + "/examples/ClientTests/compact"
0038   if args.help:
0039     logger.info("""
0040          python <dir>/ParamValue.py -option [-option]
0041               -geometry <geometry file name>  File is expected in the examples
0042                                               install area:
0043                                               """ + install_dir + """
0044               -vis                            Enable visualization
0045               -macro                          Pass G4 macro file to UI executive
0046               -batch                          Run in batch mode for unit testing
0047               -events <number>                Run geant4 for specified number of events
0048                                               (batch mode only)
0049     """)
0050     sys.exit(0)
0051 
0052   from DDG4 import OutputLevel as Output
0053   from g4units import GeV, MeV, mm
0054 
0055   kernel = DDG4.Kernel()
0056   kernel.loadGeometry(str("file:" + install_dir + os.sep + args.geometry))
0057 
0058   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0059   geant4 = DDG4.Geant4(kernel, calo='Geant4CalorimeterAction')
0060   geant4.printDetectors()
0061 
0062   # Configure UI
0063   if args.macro:
0064     ui = geant4.setupCshUI(macro=args.macro, vis=args.vis)
0065   else:
0066     ui = geant4.setupCshUI(vis=args.vis)
0067   if args.batch:
0068     ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0069 
0070   if args.sensitive:
0071     geant4.setupDetectors()
0072 
0073   # Configure field
0074   geant4.setupTrackingField(prt=True)
0075   # Configure Event actions
0076   prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0077   prt.OutputLevel = Output.DEBUG
0078   prt.OutputType = 3  # Print both: table and tree
0079   kernel.eventAction().adopt(prt)
0080 
0081   generator_output_level = Output.INFO
0082 
0083   # Configure G4 geometry setup
0084   seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0085   act.DebugMaterials = True
0086   act.DebugElements = False
0087   act.DebugVolumes = True
0088   act.DebugShapes = True
0089   seq, act = geant4.addDetectorConstruction("Geant4DetectorSensitivesConstruction/ConstructSD")
0090 
0091   # Configure I/O
0092   geant4.setupROOTOutput('RootOutput', 'ParamVolume1D_' + time.strftime('%Y-%m-%d_%H-%M'))
0093 
0094   # Setup particle gun
0095   gun = geant4.setupGun("Gun", particle='e+', energy=20 * GeV, multiplicity=1)
0096   gun.OutputLevel = generator_output_level
0097 
0098   # And handle the simulation particles.
0099   part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0100   kernel.generatorAction().adopt(part)
0101   part.SaveProcesses = ['Decay']
0102   part.MinimalKineticEnergy = 100 * MeV
0103   part.OutputLevel = Output.INFO  # generator_output_level
0104   part.enableUI()
0105   user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
0106   user.TrackingVolume_Zmax = 1 * mm
0107   user.TrackingVolume_Rmax = 1 * mm
0108   user.enableUI()
0109   part.adopt(user)
0110 
0111   # Now build the physics list:
0112   phys = geant4.setupPhysics('QGSP_BERT')
0113   ph = DDG4.PhysicsList(kernel, str('Geant4PhysicsList/Myphysics'))
0114   ph.addParticleConstructor(str('G4Geantino'))
0115   ph.addParticleConstructor(str('G4BosonConstructor'))
0116   ph.enableUI()
0117   phys.adopt(ph)
0118   phys.dump()
0119 
0120   geant4.execute()
0121 
0122 
0123 if __name__ == "__main__":
0124   run()