File indexing completed on 2026-09-09 08:23:14
0001
0002
0003 import os
0004 import time
0005 import logging
0006 import DDG4
0007 from DDG4 import OutputLevel as Output
0008 from g4units import GeV, mm, cm
0009
0010 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0011 logger = logging.getLogger(__name__)
0012
0013 """
0014
0015 dd4hep simulation example setup using the python configuration
0016
0017 @author M.Frank
0018 @version 1.0
0019
0020 import os, time, DDG4
0021 from DDG4 import OutputLevel as Output
0022 from g4units import *
0023
0024 kernel = DDG4.Kernel()
0025 description = kernel.detectorDescription()
0026 install_dir = os.environ['DD4hepINSTALL']
0027 example_dir = install_dir+'/examples/DDG4/examples';
0028 kernel.loadGeometry("file:"+install_dir+"/DDDetectors/compact/SiD_Markus.xml")
0029 kernel.loadXML("file:"+example_dir+"/DDG4_field.xml")
0030 DDG4.importConstants(description,debug=False)
0031 geant4 = DDG4.Geant4(kernel,tracker='Geant4TrackerCombineAction')
0032 geant4.printDetectors()
0033 # Configure UI
0034 geant4.setupCshUI()
0035
0036 a = DDG4.PhaseAction(kernel,'Geant4FieldPhaseAction/Geant4FieldPhaseAction_1')
0037 kernel.phase('configure').add(a)
0038
0039 kernel.configure()
0040
0041
0042 """
0043
0044
0045 def run():
0046 kernel = DDG4.Kernel()
0047 description = kernel.detectorDescription()
0048 install_dir = os.environ['DD4hepINSTALL']
0049
0050 kernel.loadGeometry(str("file:" + install_dir + "/DDDetectors/compact/SiD_Markus.xml"))
0051
0052 DDG4.importConstants(description, debug=False)
0053 geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
0054 geant4.printDetectors()
0055
0056
0057 geant4.setupCshUI()
0058 geant4.setupTrackingField()
0059
0060
0061 run1 = DDG4.RunAction(kernel, 'Geant4TestRunAction/RunInit')
0062 run1.enableUI()
0063 kernel.registerGlobalAction(run1)
0064 kernel.runAction().adopt(run1)
0065
0066
0067 prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
0068 prt.OutputLevel = Output.WARNING
0069 prt.OutputType = 3
0070 kernel.eventAction().adopt(prt)
0071
0072 generator_output_level = Output.WARNING
0073
0074
0075 geant4.setupLCIOOutput('LcioOutput', 'CLICSiD_' + time.strftime('%Y-%m-%d_%H-%M'))
0076
0077
0078
0079 prim = DDG4.GeneratorAction(kernel, "Geant4GeneratorActionInit/GenerationInit")
0080
0081 """
0082 Generation of primary particles from LCIO input files
0083 """
0084 """
0085 # First particle file reader
0086 gen = DDG4.GeneratorAction(kernel,"LCIOInputAction/LCIO1");
0087 #gen.Input = "LCIOStdHepReader|/home/frankm/SW/data/e2e2nn_gen_1343_1.stdhep"
0088 #gen.Input = "LCIOStdHepReader|/home/frankm/SW/data/qq_gen_128_999.stdhep"
0089 #gen.Input = "LCIOStdHepReader|/home/frankm/SW/data/smuonLR_PointK_3TeV_BS_noBkg_run0001.stdhep"
0090 #gen.Input = "LCIOStdHepReader|/home/frankm/SW/data/bbbb_3TeV.stdhep"
0091 #gen.Input = "LCIOFileReader|/home/frankm/SW/data/mcparticles_pi-_5GeV.slcio"
0092 #gen.Input = "LCIOFileReader|/home/frankm/SW/data/mcparticles_mu-_5GeV.slcio"
0093 #gen.Input = "LCIOFileReader|/home/frankm/SW/data/bbbb_3TeV.slcio"
0094 #gen.Input = "LCIOStdHepReader|/home/frankm/SW/data/FCC-eh.stdhep"
0095 #gen.Input = "Geant4EventReaderHepMC|/home/frankm/SW/data/data.hepmc.txt"
0096 #gen.Input = "Geant4EventReaderHepMC|/home/frankm/SW/data/sherpa-2.1.1_zjets.hepmc2g"
0097 gen.Input = "LCIOFileReader|/afs/cern.ch/user/n/nikiforo/public/Markus/muons.slcio"
0098 #gen.Input = "LCIOFileReader|/afs/cern.ch/user/n/nikiforo/public/Markus/geantinos.slcio"
0099 gen.MomentumScale = 1.0
0100 gen.Mask = 1
0101 geant4.buildInputStage([gen],output_level=generator_output_level)
0102 """
0103
0104 gen = geant4.setupGun("Gun", particle='mu+', energy=20 * GeV, position=(0 * mm, 0 * mm, 0 * cm), multiplicity=3)
0105 gen.isotrop = True
0106 gen.direction = (1, 0, 0)
0107 gen.OutputLevel = generator_output_level
0108 gen.Standalone = False
0109 """
0110 # And handle the simulation particles.
0111 part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler")
0112 kernel.generatorAction().adopt(part)
0113 #part.SaveProcesses = ['conv','Decay']
0114 part.SaveProcesses = ['Decay']
0115 part.MinimalKineticEnergy = 100*MeV
0116 part.OutputLevel = Output.INFO #generator_output_level
0117 part.enableUI()
0118 user = DDG4.Action(kernel,"Geant4TCUserParticleHandler/UserParticleHandler")
0119 user.TrackingVolume_Zmax = DDG4.EcalEndcap_zmin
0120 user.TrackingVolume_Rmax = DDG4.EcalBarrel_rmin
0121 user.enableUI()
0122 part.adopt(user)
0123 """
0124 geant4.buildInputStage([prim, gen], Output.ERROR)
0125
0126 """
0127 """
0128
0129 """
0130 rdr = DDG4.GeneratorAction(kernel,"LcioGeneratorAction/Reader")
0131 rdr.zSpread = 0.0
0132 rdr.lorentzAngle = 0.0
0133 rdr.OutputLevel = DDG4.OutputLevel.INFO
0134 rdr.Input = "LcioEventReader|test.data"
0135 rdr.enableUI()
0136 kernel.generatorAction().adopt(rdr)
0137 """
0138
0139
0140 seq, act = geant4.setupTracker('SiTrackerBarrel')
0141 seq, act = geant4.setupTracker('SiTrackerEndcap')
0142 seq, act = geant4.setupTracker('SiTrackerForward')
0143 """
0144 # Now the calorimeters
0145 seq,act = geant4.setupTracker('SiVertexBarrel')
0146 seq,act = geant4.setupTracker('SiVertexEndcap')
0147
0148 seq,act = geant4.setupCalorimeter('EcalBarrel')
0149 seq,act = geant4.setupCalorimeter('EcalEndcap')
0150 seq,act = geant4.setupCalorimeter('HcalBarrel')
0151 seq,act = geant4.setupCalorimeter('HcalEndcap')
0152 seq,act = geant4.setupCalorimeter('HcalPlug')
0153 seq,act = geant4.setupCalorimeter('MuonBarrel')
0154 seq,act = geant4.setupCalorimeter('MuonEndcap')
0155 seq,act = geant4.setupCalorimeter('LumiCal')
0156 seq,act = geant4.setupCalorimeter('BeamCal')
0157 """
0158 """
0159 scan = DDG4.SteppingAction(kernel,'Geant4MaterialScanner/MaterialScan')
0160 kernel.steppingAction().adopt(scan)
0161 """
0162
0163
0164 phys = geant4.setupPhysics('QGSP_BERT')
0165 ph = DDG4.PhysicsList(kernel, 'Geant4PhysicsList/Myphysics')
0166 ph.addParticleConstructor('G4Geantino')
0167 ph.addParticleConstructor('G4BosonConstructor')
0168 ph.enableUI()
0169 phys.adopt(ph)
0170 phys.dump()
0171
0172 kernel.configure()
0173 kernel.initialize()
0174
0175
0176 kernel.run()
0177 logger.info('End of run. Terminating .......')
0178 kernel.terminate()
0179
0180
0181 if __name__ == "__main__":
0182 run()