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 os
0015 import time
0016 import DDG4
0017 from DDG4 import OutputLevel as Output
0018 from g4units import GeV, MeV, m
0019 #
0020 #
0021 """
0022 
0023    dd4hep simulation example setup using the python configuration
0024 
0025    NOTE:
0026    If you get to the command prompt, you must not forget to enable GFlash!
0027    By default Geant4 does not enable it. Hence:
0028    Idle>  /GFlash/flag 1
0029 
0030    @author  M.Frank
0031    @version 1.0
0032 
0033 """
0034 
0035 
0036 def run():
0037   args = DDG4.CommandLine()
0038   kernel = DDG4.Kernel()
0039   install_dir = os.environ['DD4hepExamplesINSTALL']
0040   kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/SiliconBlock.xml"))
0041 
0042   DDG4.importConstants(kernel.detectorDescription(), debug=False)
0043   geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerAction', calo='Geant4CalorimeterAction')
0044   geant4.printDetectors()
0045   # Configure UI
0046   if args.macro:
0047     ui = geant4.setupCshUI(macro=args.macro)
0048   else:
0049     ui = geant4.setupCshUI()
0050   if args.batch:
0051     ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
0052 
0053   # Configure field
0054   geant4.setupTrackingField(prt=True)
0055   # Configure Event actions
0056   prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0057   prt.OutputLevel = Output.DEBUG
0058   kernel.eventAction().adopt(prt)
0059 
0060   generator_output_level = prt.OutputLevel
0061 
0062   # Configure G4 geometry setup
0063   seq, act = geant4.addDetectorConstruction('Geant4DetectorGeometryConstruction/ConstructGeo')
0064   act.DebugMaterials = True
0065   act.DebugElements = False
0066   act.DebugVolumes = True
0067   act.DebugShapes = True
0068 
0069   # Apply sensitive detectors
0070   sensitives = DDG4.DetectorConstruction(kernel, str('Geant4DetectorSensitivesConstruction/ConstructSD'))
0071   sensitives.enableUI()
0072   seq.adopt(sensitives)
0073 
0074   # Enable GFlash shower model
0075   model = DDG4.DetectorConstruction(kernel, str('Geant4Par01EMShowerModel/ShowerModel'))
0076   # Mandatory model parameters
0077   model.RegionName = 'SiRegion'
0078   model.Material = 'Silicon'
0079   model.ApplicableParticles = ['e+', 'e-']
0080   model.Etrigger = {'e+': 0.1 * GeV, 'e-': 0.1 * GeV}
0081   model.Enable = True
0082   # Energy boundaries are optional: Units are GeV
0083   model.Emin = {'e+': 0.1 * GeV, 'e-': 0.1 * GeV}
0084   model.Ekill = {'e+': 0.1 * MeV, 'e-': 0.1 * MeV}
0085   model.enableUI()
0086   seq.adopt(model)
0087 
0088   # Configure I/O
0089   geant4.setupROOTOutput('RootOutput', 'SiliconBlock_FastSim_' + time.strftime('%Y-%m-%d_%H-%M'))
0090 
0091   # Setup particle gun
0092   gun = geant4.setupGun("Gun", particle='e+', energy=50 * GeV, multiplicity=1)
0093   gun.OutputLevel = generator_output_level
0094 
0095   # And handle the simulation particles.
0096   part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
0097   kernel.generatorAction().adopt(part)
0098   part.SaveProcesses = ['Decay']
0099   part.MinimalKineticEnergy = 100 * MeV
0100   part.OutputLevel = Output.INFO  # generator_output_level
0101   part.enableUI()
0102   user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
0103   user.TrackingVolume_Zmax = 3.0 * m
0104   user.TrackingVolume_Rmax = 3.0 * m
0105   user.enableUI()
0106   part.adopt(user)
0107 
0108   geant4.setupCalorimeter('SiliconBlockUpper')
0109   geant4.setupCalorimeter('SiliconBlockDown')
0110 
0111   # Now build the physics list:
0112   phys = geant4.setupPhysics('FTFP_BERT')
0113   ph = DDG4.PhysicsList(kernel, str('Geant4FastPhysics/FastPhysicsList'))
0114   ph.EnabledParticles = ['e+', 'e-']
0115   ph.BeVerbose = True
0116   ph.enableUI()
0117   phys.adopt(ph)
0118   phys.dump()
0119 
0120   geant4.execute()
0121 
0122 
0123 if __name__ == "__main__":
0124   run()