Back to home page

EIC code displayed by LXR

 
 

    


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

0001 
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 #
0014 from __future__ import absolute_import, unicode_literals
0015 import os
0016 import DDG4
0017 from DDG4 import OutputLevel as Output
0018 from g4units import GeV, MeV, m, cm
0019 #
0020 #
0021 """
0022 
0023    dd4hep simulation example setup using the python configuration
0024 
0025    @author  M.Frank
0026    @version 1.0
0027 
0028 """
0029 
0030 
0031 def run():
0032   args = DDG4.CommandLine()
0033   kernel = DDG4.Kernel()
0034   install_dir = os.environ['DD4hepExamplesINSTALL']
0035   kernel.loadGeometry(str("file:" + install_dir + "/examples/AlignDet/compact/AlephTPC.xml"))
0036 
0037   if args.alignments:
0038     kernel.loadXML(str("file:") + str(args.alignments))
0039 
0040   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0041   geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0042   geant4.printDetectors()
0043   # Configure UI
0044   if args.macro:
0045     ui = geant4.setupCshUI(macro=args.macro)
0046   else:
0047     ui = geant4.setupCshUI()
0048   if args.batch:
0049     ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0050 
0051   # Configure field
0052   geant4.setupTrackingField(prt=True)
0053   # Configure Event actions
0054   prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0055   prt.OutputLevel = Output.DEBUG
0056   prt.OutputType = 3  # Print both: table and tree
0057   kernel.eventAction().adopt(prt)
0058 
0059   generator_output_level = Output.INFO
0060 
0061   # Configure G4 geometry setup
0062   seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
0063   act.DebugMaterials = True
0064   act.DebugElements = False
0065   act.DebugVolumes = True
0066   act.DebugShapes = True
0067   seq, act = geant4.addDetectorConstruction("Geant4DetectorSensitivesConstruction/ConstructSD")
0068 
0069   # Setup particle gun
0070   pos = (0.0, 0.0, -364.0 * cm)
0071   gun = geant4.setupGun("Gun", particle='e+', energy=50 * GeV, multiplicity=1, position=pos)
0072   gun.OutputLevel = generator_output_level
0073 
0074   # And handle the simulation particles.
0075   part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0076   kernel.generatorAction().adopt(part)
0077   part.SaveProcesses = ['Decay']
0078   part.MinimalKineticEnergy = 100 * MeV
0079   part.OutputLevel = Output.INFO  # generator_output_level
0080   part.enableUI()
0081   user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
0082   user.TrackingVolume_Zmax = 3.0 * m
0083   user.TrackingVolume_Rmax = 3.0 * m
0084   user.enableUI()
0085   part.adopt(user)
0086 
0087   geant4.setupTracker('TPC')
0088 
0089   # Now build the physics list:
0090   phys = geant4.setupPhysics('QGSP_BERT')
0091   phys.dump()
0092   geant4.execute()
0093 
0094 
0095 if __name__ == "__main__":
0096   run()