trackers/compact/scripts/debug_sim.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 from __future__ import absolute_import, unicode_literals
4 import os
5 import time
6 import logging
7 import DDG4
8 from DDG4 import OutputLevel as Output
9 from g4units import keV, GeV, mm, ns, MeV
10 from pprint import pprint
11 
12 def run():
13  os.environ['G4UI_USE_TCSH'] = "1"
14  kernel = DDG4.Kernel()
15  description = kernel.detectorDescription()
16  kernel.loadGeometry(str("file:" + "GenericRICH_example.xml"))
17  DDG4.importConstants(description)
18 
19  geant4 = DDG4.Geant4(kernel)
20  geant4.printDetectors()
21 
22  rootoutput = geant4.setupROOTOutput('RootOutput', 'derp_' + time.strftime('%Y-%m-%d_%H-%M'), mc_truth=True)
23  rootoutput.HandleMCTruth = True
24 
25  geant4.setupUI('tcsh',vis=False,macro='macro/gps.mac')
26  geant4.setupTrackingField()
27 
28  # Do not use this gun setup helper!
29  #geant4.setupGun('electron','e-',3.0*GeV)
30 
31  gen = DDG4.GeneratorAction(kernel, "Geant4GeneratorActionInit/GenerationInit")
32  kernel.generatorAction().adopt(gen)
33  gen.enableUI()
34 
35  gun = DDG4.GeneratorAction(kernel, "Geant4GeneratorWrapper/Gun")
36  gun.Uses = 'G4ParticleGun'
37  gun.Mask = 1
38  kernel.generatorAction().adopt(gun)
39 
40  gen = DDG4.GeneratorAction(kernel, "Geant4ParticleGenerator/ElectronGenerator")
41  gen.Mask = 1 # no idea what this does
42  gen.Particle = 'e-'
43  gen.Energy = 5 * GeV
44  gen.Multiplicity = 1
45  #gen.Direction = 'uniform'
46 
47  gen = DDG4.GeneratorAction(kernel, "Geant4InteractionMerger/InteractionMerger")
48  gen.OutputLevel = 0 # generator_output_level
49  gen.enableUI()
50  kernel.generatorAction().adopt(gen)
51 
52  gen = DDG4.GeneratorAction(kernel, "Geant4PrimaryHandler/PrimaryHandler")
53  #gen.OutputLevel = 0 # generator_output_level
54  gen.enableUI()
55  kernel.generatorAction().adopt(gen)
56 
57  # Particle handler is critical for saving MCParticles
58  part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
59  kernel.generatorAction().adopt(part)
60  # part.SaveProcesses = ['conv','Decay']
61  part.SaveProcesses = ['Decay']
62  part.MinimalKineticEnergy = 100 * MeV
63  #part.OutputLevel = 5 # generator_output_level
64  part.enableUI()
65 
66  #part.adopt(user)
67  #user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
68  #user.TrackingVolume_Zmax = DDG4.EcalEndcap_zmin
69  #user.TrackingVolume_Rmax = DDG4.EcalBarrel_rmin
70  #user.enableUI()
71 
72  #f1 = DDG4.Filter(kernel, 'GeantinoRejectFilter/GeantinoRejector')
73  f2 = DDG4.Filter(kernel, 'ParticleRejectFilter/OpticalPhotonRejector')
74  f2.particle = 'opticalphoton'
75  f3 = DDG4.Filter(kernel, 'ParticleSelectFilter/OpticalPhotonSelector')
76  f3.particle = 'opticalphoton'
77  #f4 = DDG4.Filter(kernel, 'EnergyDepositMinimumCut')
78  #f4.Cut = 10 * MeV
79  #f4.enableUI()
80 
81  #kernel.registerGlobalFilter(f1)
82  kernel.registerGlobalFilter(f2)
83  kernel.registerGlobalFilter(f3)
84  #kernel.registerGlobalFilter(f4)
85 
86  seq, act = geant4.setupDetector('ForwardRICH','PhotoMultiplierSDAction')
87  act.adopt(f2)
88 
89  phys = geant4.setupPhysics('QGSP_BERT')
90  geant4.addPhysics(str('Geant4PhysicsList/Myphysics'))
91  phys.enableUI()
92 
93  ph = DDG4.PhysicsList(kernel, 'Geant4OpticalPhotonPhysics/OpticalPhotonPhys')
94  ph.VerboseLevel = 0
95  ph.enableUI()
96  phys.adopt(ph)
97 
98  ph = DDG4.PhysicsList(kernel, 'Geant4CerenkovPhysics/CerenkovPhys')
99  ph.MaxNumPhotonsPerStep = 10
100  ph.MaxBetaChangePerStep = 10.0
101  ph.TrackSecondariesFirst = True
102  ph.VerboseLevel = 0
103  ph.enableUI()
104  phys.adopt(ph)
105 
106  #gun.generator() # Instantiate gun to be able to set properties from G4 prompt
107  kernel.configure()
108  kernel.initialize()
109 
110  # DDG4.setPrintLevel(Output.DEBUG)
111  kernel.run()
112  kernel.terminate()
113 
114 
115 if __name__ == "__main__":
116  run()
def Filter(kernel, nam, shared=False)
Definition: DDG4.py:185
Kernel
Definition: DDG4.py:67
def PhysicsList(kernel, nam)
Definition: DDG4.py:221
def GeneratorAction(kernel, nam, shared=False)
Definition: DDG4.py:201
def importConstants(description, namespace=None, debug=False)
Definition: DDG4.py:79