[1337] | 1 | #!/usr/bin/python |
---|
| 2 | # ================================================================== |
---|
| 3 | # python script for Geant4Py test |
---|
| 4 | # |
---|
| 5 | # gtest02 |
---|
| 6 | # - test for using site-module packages |
---|
| 7 | # ================================================================== |
---|
| 8 | from Geant4 import * |
---|
| 9 | import g4py.Qmaterials, g4py.NISTmaterials |
---|
| 10 | import g4py.Qgeom, g4py.ExN01geom, g4py.ExN03geom |
---|
| 11 | import g4py.ExN01pl, g4py.EMSTDpl |
---|
| 12 | import g4py.ParticleGun, g4py.MedicalBeam |
---|
| 13 | |
---|
| 14 | # ================================================================== |
---|
| 15 | # user setup |
---|
| 16 | # ================================================================== |
---|
| 17 | |
---|
| 18 | # ------------------------------------------------------------------ |
---|
| 19 | # Setup-0 (Q) |
---|
| 20 | # ------------------------------------------------------------------ |
---|
| 21 | def Setup0(): |
---|
| 22 | # simple materials for Qgeom |
---|
| 23 | g4py.Qmaterials.Construct() |
---|
| 24 | |
---|
| 25 | # NIST materials |
---|
| 26 | #g4py.NISTmaterials.Construct() |
---|
| 27 | |
---|
| 28 | # normal way for constructing user geometry |
---|
| 29 | #qDC= g4py.Qgeom.QDetectorConstruction() |
---|
| 30 | #gRunManager.SetUserInitialization(qDC) |
---|
| 31 | |
---|
| 32 | # 2nd way, short-cut way |
---|
| 33 | g4py.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 | g4py.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= g4py.ExN03geom.ExN03DetectorConstruction() |
---|
| 57 | #gRunManager.SetUserInitialization(exN03geom) |
---|
| 58 | |
---|
| 59 | g4py.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(20050830L) |
---|
| 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 | #g4py.ExN01pl.Construct() |
---|
| 94 | |
---|
| 95 | # electron/gamma standard EM |
---|
| 96 | g4py.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= g4py.ParticleGun.ParticleGunAction() |
---|
| 106 | #gRunManager.SetUserAction(pgPGA) |
---|
| 107 | #pg= pgPGA.GetParticleGun() |
---|
| 108 | |
---|
| 109 | # 2nd way, short-cut way |
---|
| 110 | pg= g4py.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= g4py.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 | |
---|