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