ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file test.py
1 #!/usr/bin/python3
2 # ==================================================================
3 # python script for Geant4Py test
4 #
5 # gtest02
6 # - test for using site-module packages
7 # ==================================================================
8 from Geant4 import *
13 
14 # ==================================================================
15 # user setup
16 # ==================================================================
17 
18 # ------------------------------------------------------------------
19 # Setup-0 (Q)
20 # ------------------------------------------------------------------
21 def Setup0():
22  # simple materials for Qgeom
23  g4pytest.Qmaterials.Construct()
24 
25  # NIST materials
26  #g4pytest.NISTmaterials.Construct()
27 
28  # normal way for constructing user geometry
29  #qDC= g4pytest.Qgeom.QDetectorConstruction()
30  #gRunManager.SetUserInitialization(qDC)
31 
32  # 2nd way, short-cut way
33  g4pytest.Qgeom.Construct()
34 
35  # primary
36  global primary_position, primary_direction
37  primary_position= G4ThreeVector(0.,0., -14.9*cm)
38  primary_direction= G4ThreeVector(0.2, 0., 1.)
39 
40 
41 # ------------------------------------------------------------------
42 # Setup-1 (ExampleN01)
43 # ------------------------------------------------------------------
44 def Setup1():
45  g4pytest.ExN01geom.Construct()
46 
47  global primary_position, primary_direction
48  primary_position= G4ThreeVector(-2.5*m, 0., 0.)
49  primary_direction= G4ThreeVector(1., 0., 0.)
50 
51 
52 # ------------------------------------------------------------------
53 # Setup-3 (ExampleN03)
54 # ------------------------------------------------------------------
55 def Setup3():
56  #exN03geom= g4pytest.ExN03geom.ExN03DetectorConstruction()
57  #gRunManager.SetUserInitialization(exN03geom)
58 
59  g4pytest.ExN03geom.Construct()
60 
61  global primary_position, primary_direction
62  primary_position= G4ThreeVector(-1.*m, 0., 0.)
63  primary_direction= G4ThreeVector(1., 0., 0.)
64 
65 
66 # ==================================================================
67 # main
68 # ==================================================================
69 # ------------------------------------------------------------------
70 # randum number
71 # ------------------------------------------------------------------
72 rand_engine= Ranlux64Engine()
73 HepRandom.setTheEngine(rand_engine)
74 HepRandom.setTheSeed(20050830)
75 
76 # ------------------------------------------------------------------
77 # user setup
78 # ------------------------------------------------------------------
79 Setup0()
80 #Setup1()
81 #Setup3()
82 
83 
84 # ------------------------------------------------------------------
85 # setup for physics list
86 # ------------------------------------------------------------------
87 # normal way for constructing user physics list
88 #exN01PL= ExN01PhysicsList.ExN01PhysicsList()
89 #gRunManager.SetUserInitialization(exN01PL)
90 
91 # 2nd way, short-cut way
92 # geantino + transportation
93 #g4pytest.ExN01pl.Construct()
94 
95 # electron/gamma standard EM
96 g4pytest.EMSTDpl.Construct()
97 
98 # ------------------------------------------------------------------
99 # setup for primary generator action
100 # ------------------------------------------------------------------
101 # ------------
102 # Particle Gun
103 # ------------
104 # normal way for constructing user physics list
105 #pgPGA= g4pytest.ParticleGun.ParticleGunAction()
106 #gRunManager.SetUserAction(pgPGA)
107 #pg= pgPGA.GetParticleGun()
108 
109 # 2nd way, short-cut way
110 pg= g4pytest.ParticleGun.Construct()
111 
112 # set parameters of particle gun
113 pg.SetParticleByName("e-")
114 pg.SetParticleEnergy(300.*MeV)
115 pg.SetParticlePosition(primary_position)
116 pg.SetParticleMomentumDirection(primary_direction)
117 
118 # ------------
119 # Medical Beam
120 # ------------
121 #beam= g4pytest.MedicalBeam.Construct()
122 
123 # ------------------------------------------------------------------
124 # go...
125 # ------------------------------------------------------------------
126 gRunManager.Initialize()
127 
128 # visualization
129 gApplyUICommand("/control/execute vis.mac")
130 
131 # beamOn
132 #gRunManager.BeamOn(3)
133