Newer
Older
import os, time, DDG4
from DDG4 import OutputLevel as Output
Markus Frank
committed
print \
DD4hep simulation example setup using the python configuration
@author M.Frank
@version 1.0
"""
def run():
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
print "# Configure UI"
geant4.setupCshUI()
Markus Frank
committed
print "# Configure G4 magnetic field tracking"
Markus Frank
committed
field = geant4.addConfig('Geant4FieldTrackingSetupAction/MagFieldTrackingSetup')
field.stepper = "HelixGeant4Runge"
Markus Frank
committed
field.equation = "Mag_UsualEqRhs"
field.eps_min = 5e-05 * mm
field.eps_max = 0.001 * mm
field.min_chord_step = 0.01 * mm
field.delta_chord = 0.25 * mm
field.delta_intersection = 1e-05 * mm
field.delta_one_step = 0.001 * mm
print '+++++> ',field.name,'-> stepper = ',field.stepper
print '+++++> ',field.name,'-> equation = ',field.equation
print '+++++> ',field.name,'-> eps_min = ',field.eps_min
print '+++++> ',field.name,'-> eps_max = ',field.eps_max
print '+++++> ',field.name,'-> delta_one_step = ',field.delta_one_step
Markus Frank
committed
print "# 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
print "# Configure Run actions"
run1 = DDG4.RunAction(kernel,'Geant4TestRunAction/RunInit')
run1.Property_int = 12345
run1.Property_double = -5e15*keV
run1.Property_string = 'Startrun: Hello_2'
print run1.Property_string, run1.Property_double, run1.Property_int
run1.enableUI()
kernel.registerGlobalAction(run1)
Markus Frank
committed
print "# Configure Event actions"
prt = DDG4.EventAction(kernel,'Geant4ParticlePrint/ParticlePrint')
prt.OutputLevel = Output.INFO
prt.OutputType = 3 # Print both: table and tree
Markus Frank
committed
print """
Configure I/O
"""
evt_lcio = geant4.setupLCIOOutput('LcioOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M'))
evt_root = geant4.setupROOTOutput('RootOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M'))
gen = DDG4.GeneratorAction(kernel,"Geant4GeneratorActionInit/GenerationInit")
#VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Markus Frank
committed
print """
Generation of isotrope tracks of a given multiplicity with overlay:
Markus Frank
committed
print "# First particle generator: pi+"
gen = DDG4.GeneratorAction(kernel,"Geant4IsotropeGenerator/IsotropPi+");
Markus Frank
committed
gen.Mask = 1
Markus Frank
committed
gen.Energy = 100 * GeV
kernel.generatorAction().adopt(gen)
Markus Frank
committed
print "# 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
print "# Second particle generator: e-"
gen = DDG4.GeneratorAction(kernel,"Geant4IsotropeGenerator/IsotropE-");
Markus Frank
committed
gen.Mask = 2
Markus Frank
committed
gen.Energy = 25 * GeV
kernel.generatorAction().adopt(gen)
Markus Frank
committed
print " 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
print "# Merge all existing interaction records"
gen = DDG4.GeneratorAction(kernel,"Geant4InteractionMerger/InteractionMerger")
gen.OutputLevel = 4 #generator_output_level
kernel.generatorAction().adopt(gen)
Markus Frank
committed
print "# Finally generate Geant4 primaries"
gen = DDG4.GeneratorAction(kernel,"Geant4PrimaryHandler/PrimaryHandler")
gen.OutputLevel = 4 #generator_output_level
kernel.generatorAction().adopt(gen)
Markus Frank
committed
print "# ....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)
Markus Frank
committed
print "# Setup global filters fur use in sensntive 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
print "# 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
print "# 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
print "# 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()