"git@code.ihep.ac.cn:cinema-developers/xerces-c.git" did not exist on "c0b86e1b15c13a54a180df08cd5725bdf5c42fc1"
Newer
Older
Markus Frank
committed
import os, time, logging, DDG4
Markus Frank
committed
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
logging.info(
dd4hep simulation example setup using the python configuration
Markus Frank
committed
""")
install_dir = os.environ['DD4hepINSTALL']
kernel.loadGeometry("file:"+install_dir+"/DDDetectors/compact/SiD.xml")
geant4 = DDG4.Geant4(kernel,tracker='Geant4TrackerCombineAction')
geant4.printDetectors()
Markus Frank
committed
logging.info("# Configure UI")
geant4.setupCshUI()
Markus Frank
committed
logging.info("# Configure G4 magnetic field tracking")
geant4.setupTrackingField()
logging.info("# Setup random generator")
rndm = DDG4.Action(kernel,'Geant4Random/Random')
rndm.Seed = 987654321
rndm.initialize()
Markus Frank
committed
##rndm.showStatus()
Markus Frank
committed
Markus Frank
committed
logging.info("# Configure Run actions")
run1 = DDG4.RunAction(kernel,'Geant4TestRunAction/RunInit')
run1.Property_int = 12345
run1.Property_double = -5e15*keV
run1.Property_string = 'Startrun: Hello_2'
Markus Frank
committed
logging.info("%s %s %s",run1.Property_string, str(run1.Property_double), str(run1.Property_int))
run1.enableUI()
kernel.registerGlobalAction(run1)
Markus Frank
committed
logging.info("# Configure Event actions")
prt = DDG4.EventAction(kernel,'Geant4ParticlePrint/ParticlePrint')
prt.OutputLevel = Output.INFO
prt.OutputType = 3 # Print both: table and tree
Markus Frank
committed
logging.info("""
Markus Frank
committed
Configure I/O
Markus Frank
committed
""")
#evt_lcio = geant4.setupLCIOOutput('LcioOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M'))
#evt_lcio.OutputLevel = Output.ERROR
evt_root = geant4.setupROOTOutput('RootOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M'))
gen = DDG4.GeneratorAction(kernel,"Geant4GeneratorActionInit/GenerationInit")
#VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Markus Frank
committed
logging.info("""
Generation of isotrope tracks of a given multiplicity with overlay:
Markus Frank
committed
""")
logging.info("# First particle generator: pi+")
gen = DDG4.GeneratorAction(kernel,"Geant4IsotropeGenerator/IsotropPi+");
Markus Frank
committed
gen.Mask = 1
Markus Frank
committed
gen.Energy = 100 * GeV
gen.Distribution = 'cos(theta)'
kernel.generatorAction().adopt(gen)
Markus Frank
committed
logging.info("# Install vertex smearing for this interaction")
gen = DDG4.GeneratorAction(kernel,"Geant4InteractionVertexSmear/SmearPi+");
Markus Frank
committed
gen.Mask = 1
gen.Offset = (20*mm, 10*mm, 10*mm, 0*ns)
Markus Frank
committed
gen.Sigma = (4*mm, 1*mm, 1*mm, 0*ns)
kernel.generatorAction().adopt(gen)
Markus Frank
committed
logging.info("# Second particle generator: e-")
gen = DDG4.GeneratorAction(kernel,"Geant4IsotropeGenerator/IsotropE-");
Markus Frank
committed
gen.Mask = 2
Markus Frank
committed
gen.Energy = 25 * GeV
gen.Distribution = 'uniform'
kernel.generatorAction().adopt(gen)
Markus Frank
committed
logging.info(" Install vertex smearing for this interaction")
gen = DDG4.GeneratorAction(kernel,"Geant4InteractionVertexSmear/SmearE-");
Markus Frank
committed
gen.Mask = 2
gen.Offset = (-20*mm, -10*mm, -10*mm, 0*ns)
Markus Frank
committed
gen.Sigma = (12*mm, 8*mm, 8*mm, 0*ns)
kernel.generatorAction().adopt(gen)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Markus Frank
committed
logging.info("# Merge all existing interaction records")
gen = DDG4.GeneratorAction(kernel,"Geant4InteractionMerger/InteractionMerger")
gen.OutputLevel = 4 #generator_output_level
kernel.generatorAction().adopt(gen)
Markus Frank
committed
logging.info("# Finally generate Geant4 primaries")
gen = DDG4.GeneratorAction(kernel,"Geant4PrimaryHandler/PrimaryHandler")
gen.OutputLevel = 4 #generator_output_level
kernel.generatorAction().adopt(gen)
Markus Frank
committed
logging.info("# ....and handle the simulation particles.")
part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler")
kernel.generatorAction().adopt(part)
#part.SaveProcesses = ['conv','Decay']
part.SaveProcesses = ['Decay']
part.MinimalKineticEnergy = 100*MeV
part.OutputLevel = 5 # generator_output_level
part.enableUI()
user = DDG4.Action(kernel,"Geant4TCUserParticleHandler/UserParticleHandler")
user.TrackingVolume_Zmax = DDG4.EcalEndcap_zmin
user.TrackingVolume_Rmax = DDG4.EcalBarrel_rmin
user.enableUI()
part.adopt(user)
logging.info("# Setup global filters fur use in sensitive detectors")
f1 = DDG4.Filter(kernel,'GeantinoRejectFilter/GeantinoRejector')
f2 = DDG4.Filter(kernel,'ParticleRejectFilter/OpticalPhotonRejector')
f2.particle = 'opticalphoton'
f3 = DDG4.Filter(kernel,'ParticleSelectFilter/OpticalPhotonSelector')
f3.particle = 'opticalphoton'
f4 = DDG4.Filter(kernel,'EnergyDepositMinimumCut')
f4.Cut = 10*MeV
f4.enableUI()
kernel.registerGlobalFilter(f1)
kernel.registerGlobalFilter(f2)
kernel.registerGlobalFilter(f3)
kernel.registerGlobalFilter(f4)
Markus Frank
committed
logging.info("# First the tracking detectors")
seq,act = geant4.setupTracker('SiVertexBarrel')
seq.adopt(f1)
#seq.adopt(f4)
act.adopt(f1)
seq,act = geant4.setupTracker('SiVertexEndcap')
seq,act = geant4.setupTracker('SiTrackerBarrel')
seq,act = geant4.setupTracker('SiTrackerEndcap')
seq,act = geant4.setupTracker('SiTrackerForward')
Markus Frank
committed
logging.info("# Now setup the calorimeters")
seq,act = geant4.setupCalorimeter('EcalBarrel')
seq,act = geant4.setupCalorimeter('EcalEndcap')
seq,act = geant4.setupCalorimeter('HcalBarrel')
seq,act = geant4.setupCalorimeter('HcalEndcap')
seq,act = geant4.setupCalorimeter('HcalPlug')
seq,act = geant4.setupCalorimeter('MuonBarrel')
seq,act = geant4.setupCalorimeter('MuonEndcap')
seq,act = geant4.setupCalorimeter('LumiCal')
seq,act = geant4.setupCalorimeter('BeamCal')
Markus Frank
committed
logging.info("# Now build the physics list:")
phys = geant4.setupPhysics('QGSP_BERT')
ph = geant4.addPhysics('Geant4PhysicsList/Myphysics')
#ph.addParticleConstructor('G4BosonConstructor')
#ph.addParticleConstructor('G4LeptonConstructor')
#ph.addParticleProcess('e[+-]','G4eMultipleScattering',-1,1,1)
#ph.addPhysicsConstructor('G4OpticalPhysics')
# Add special particle types from specialized physics constructor
part = geant4.addPhysics('Geant4ExtraParticles/ExtraParticles')
part.pdgfile = 'checkout/DDG4/examples/particle.tbl'
# Add global range cut
rg = geant4.addPhysics('Geant4DefaultRangeCut/GlobalRangeCut')
rg.RangeCut = 0.7*mm
phys.dump()
kernel.configure()
kernel.initialize()
kernel.run()
kernel.terminate()
if __name__ == "__main__":
run()